{"id":13395080,"url":"https://github.com/gottfrois/link_thumbnailer","last_synced_at":"2025-05-15T08:09:35.271Z","repository":{"id":4234610,"uuid":"5358289","full_name":"gottfrois/link_thumbnailer","owner":"gottfrois","description":"Ruby gem that fetches images and metadata from a given URL. Much like popular social website with link preview.","archived":false,"fork":false,"pushed_at":"2023-08-16T21:12:08.000Z","size":703,"stargazers_count":513,"open_issues_count":13,"forks_count":107,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-04-14T12:18:40.464Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gottfrois.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2012-08-09T16:43:03.000Z","updated_at":"2025-02-26T14:12:21.000Z","dependencies_parsed_at":"2024-01-08T18:03:34.953Z","dependency_job_id":"4c369d24-ce24-4bd1-b3d5-b6911ad2043b","html_url":"https://github.com/gottfrois/link_thumbnailer","commit_stats":{"total_commits":247,"total_committers":30,"mean_commits":8.233333333333333,"dds":0.2510121457489879,"last_synced_commit":"96c8061e81e1fed7750ed72ebe84eeb3cb3a5e4a"},"previous_names":[],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gottfrois%2Flink_thumbnailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gottfrois%2Flink_thumbnailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gottfrois%2Flink_thumbnailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gottfrois%2Flink_thumbnailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gottfrois","download_url":"https://codeload.github.com/gottfrois/link_thumbnailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877968,"owners_count":21176244,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T17:01:41.321Z","updated_at":"2025-04-14T12:18:52.793Z","avatar_url":"https://github.com/gottfrois.png","language":"Ruby","funding_links":[],"categories":["Web Apps, Services \u0026 Interaction","Ruby","Web Crawling","Uncategorized"],"sub_categories":["Web Content Scrapers","Uncategorized"],"readme":"# LinkThumbnailer\n\n[![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)\n[![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)\n[![Gem Version](https://badge.fury.io/rb/link_thumbnailer.svg)](http://badge.fury.io/rb/link_thumbnailer)\n\nRuby gem generating image thumbnails from a given URL. Rank them and give you back an object containing images and website informations. Works like Facebook link previewer.\n\nDemo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !\nThe source code of the Demo Application is hosted [here](https://github.com/gottfrois/link_thumbnailer_demo)!\n\n## Features\n\n- Dead simple.\n- Support [OpenGraph](http://ogp.me/) protocol.\n- Find and sort images that best represent what the page is about.\n- Find and rate description that best represent what the page is about.\n- Allow for custom class to sort the website descriptions yourself.\n- Support image urls blacklisting (advertisements).\n- Works with and without Rails.\n- Fully customizable.\n- Fully tested.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'link_thumbnailer'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install link_thumbnailer\n\nIf you are using Rails, you can generate the configuration file with:\n\n\t$ rails g link_thumbnailer:install\n\nThis will add `link_thumbnailer.rb` to `config/initializers/`.\n\n## Usage\n\nRun `irb` and require the gem:\n\n```ruby\nrequire 'link_thumbnailer'\n```\n\nThe gem handle regular website but also website that use the [Opengraph](http://ogp.me/) protocol.\n\n```ruby\nobject = LinkThumbnailer.generate('http://stackoverflow.com')\n =\u003e #\u003cLinkThumbnailer::Models::Website:...\u003e\n\nobject.title\n =\u003e \"Stack Overflow\"\n\nobject.favicon\n =\u003e \"//cdn.sstatic.net/stackoverflow/img/favicon.ico?v=038622610830\"\n\nobject.description\n =\u003e \"Q\u0026A for professional and enthusiast programmers\"\n\nobject.images.first.src.to_s\n =\u003e \"http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6\"\n```\n\nLinkThumbnailer `generate` method return an instance of `LinkThumbnailer::Models::Website` that respond to `to_json` and `as_json` as you would expect:\n\n```ruby\nobject.to_json\n =\u003e \"{\\\"url\\\":\\\"http://stackoverflow.com\\\",\\\"title\\\":\\\"Stack Overflow\\\",\\\"description\\\":\\\"Q\u0026A for professional and enthusiast programmers\\\",\\\"images\\\":[{\\\"src\\\":\\\"http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=fde65a5a78c6\\\",\\\"size\\\":[316,316],\\\"type\\\":\\\"png\\\"}]}\"\n```\n\n\n## Configuration\n\nLinkThumbnailer comes with default configuration values. You can change default value by overriding them in a rails initializer:\n\nIn `config/initializers/link_thumbnailer.rb`\n\n```ruby\nLinkThumbnailer.configure do |config|\n  # Numbers of redirects before raising an exception when trying to parse given url.\n  #\n  # config.redirect_limit = 3\n\n  # Set user agent\n  #\n  # config.user_agent = 'link_thumbnailer'\n\n  # Enable or disable SSL verification\n  #\n  # config.verify_ssl = true\n\n  # The amount of time in seconds to wait for a connection to be opened.\n  # If the HTTP object cannot open a connection in this many seconds,\n  # it raises a Net::OpenTimeout exception.\n  #\n  # See http://www.ruby-doc.org/stdlib-2.1.1/libdoc/net/http/rdoc/Net/HTTP.html#open_timeout\n  #\n  # config.http_open_timeout = 5\n\n  # List of blacklisted urls you want to skip when searching for images.\n  #\n  # config.blacklist_urls = [\n  #   %r{^http://ad\\.doubleclick\\.net/},\n  #   %r{^http://b\\.scorecardresearch\\.com/},\n  #   %r{^http://pixel\\.quantserve\\.com/},\n  #   %r{^http://s7\\.addthis\\.com/}\n  # ]\n\n  # List of attributes you want LinkThumbnailer to fetch on a website.\n  #\n  # config.attributes = [:title, :images, :description, :videos, :favicon]\n\n  # List of procedures used to rate the website description. Add you custom class\n  # here. See wiki for more details on how to build your own graders.\n  #\n  # config.graders = [\n  #   -\u003e(description) { ::LinkThumbnailer::Graders::Length.new(description) },\n  #   -\u003e(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :class) },\n  #   -\u003e(description) { ::LinkThumbnailer::Graders::HtmlAttribute.new(description, :id) },\n  #   -\u003e(description) { ::LinkThumbnailer::Graders::Position.new(description, weight: 3) },\n  #   -\u003e(description) { ::LinkThumbnailer::Graders::LinkDensity.new(description) }\n  # ]\n\n  # Minimum description length for a website.\n  #\n  # config.description_min_length = 25\n\n  # Regex of words considered positive to rate website description.\n  #\n  # config.positive_regex = /article|body|content|entry|hentry|main|page|pagination|post|text|blog|story/i\n\n  # Regex of words considered negative to rate website description.\n  #\n  # config.negative_regex = /combx|comment|com-|contact|foot|footer|footnote|masthead|media|meta|outbrain|promo|related|scroll|shoutbox|sidebar|sponsor|shopping|tags|tool|widget|modal/i\n\n  # Numbers of images to fetch. Fetching too many images will be slow.\n  # Note that LinkThumbnailer will only sort fetched images between each other.\n  # Meaning that they could be a \"better\" image on the page.\n  #\n  # config.image_limit = 5\n\n  # Whether you want LinkThumbnailer to return image size and type or not.\n  # Setting this value to false will increase performance since for each images, LinkThumbnailer\n  # does not have to fetch its size and type.\n  #\n  # config.image_stats = true\n  #\n  # Whether you want LinkThumbnailer to raise an exception if the Content-Type of the HTTP request\n  # is not an html or xml.\n  #\n  # config.raise_on_invalid_format = false\n  #\n  # Sets number of concurrent http connections that can be opened to fetch images informations such as size and type.\n  #\n  # config.max_concurrency = 20\n\n  # Sets the default encoding.\n  #\n  # config.encoding = 'utf-8'\nend\n```\n\nOr at runtime:\n\n```ruby\nobject = LinkThumbnailer.generate('http://stackoverflow.com', redirect_limit: 5, user_agent: 'foo')\n```\n\nNote that runtime options will override default global configuration.\n\nSee [Configuration Options Explained](https://github.com/gottfrois/link_thumbnailer/wiki/Configuration-options-explained) for more details on each configuration options.\n\n## Exceptions\n\nLinkThumbnailer defines a list of custom exceptions you may want to rescue in your code. All the following exceptions inherit from `LinkThumbnailer::Exceptions`:\n\n* `RedirectLimit` -- raised when redirection threshold defined in config is reached\n* `BadUriFormat` -- raised when url given is not a valid HTTP url\n* `FormatNotSupported` -- raised when the `Content-Type` of the HTTP request is not supported (not `html`)\n\nYou can rescue from any LinkThumbnailer exceptions using the following code:\n\n```ruby\nbegin\n  LinkThumbnailer.generate('http://foo.com')\nrescue LinkThumbnailer::Exceptions =\u003e e\n  # do something\nend\n```\n\n## Contributing\n\n1. Fork it\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Run the specs (`bundle exec rspec spec`)\n4. Commit your changes (`git commit -am 'Added some feature'`)\n5. Push to the branch (`git push origin my-new-feature`)\n6. Create new Pull Request\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgottfrois%2Flink_thumbnailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgottfrois%2Flink_thumbnailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgottfrois%2Flink_thumbnailer/lists"}