link_thumbnailer 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.md +104 -100
- data/LICENSE +21 -21
- data/README.md +184 -184
- data/lib/generators/templates/initializer.rb +41 -41
- data/lib/link_thumbnailer/configuration.rb +17 -17
- data/lib/link_thumbnailer/doc.rb +65 -65
- data/lib/link_thumbnailer/doc_parser.rb +15 -15
- data/lib/link_thumbnailer/engine.rb +4 -4
- data/lib/link_thumbnailer/fetcher.rb +34 -34
- data/lib/link_thumbnailer/img_comparator.rb +17 -17
- data/lib/link_thumbnailer/img_parser.rb +41 -41
- data/lib/link_thumbnailer/img_url_filter.rb +13 -13
- data/lib/link_thumbnailer/object.rb +41 -41
- data/lib/link_thumbnailer/opengraph.rb +20 -20
- data/lib/link_thumbnailer/railtie.rb +9 -9
- data/lib/link_thumbnailer/version.rb +3 -3
- data/lib/link_thumbnailer/web_image.rb +19 -19
- data/lib/link_thumbnailer.rb +119 -119
- data/link_thumbnailer.gemspec +28 -28
- data/spec/link_thumbnailer_spec.rb +205 -205
- data/spec/spec_helper.rb +13 -13
- data/spec/web_image_spec.rb +57 -57
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTI4ZDFkMDdhMWJiM2Y2M2ZlODEwMTg1NjU4MDg3NWIxNDg1NmVkMw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZGY2MzVlMTM1OGQxNWEwODNjMDM2ZGIyNDIwZjAzNWZiNjI5ZmEzNA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTRlNGI4Yjk2Njk2MDgwNTI2YTgyMGJlNDdmMTk2Y2Q4YjEyY2UyODAyOGU5
|
10
|
+
YTk0ZTJjOTg5YWJjZDBjN2U5NWM2ODg3YzRiNGY3ZGYzZGU3NTE0YzE2YjM3
|
11
|
+
MDIyM2UwNTQ3MmJkZWY4YzcwZjkzNWU0ZjRiNzNmMmViNzA2MTM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGI4ZjIwNWEzODIwN2E4YjA0MGVjYWY1NzUzZGE0Njk3MzcxOTA0Zjk3OGY5
|
14
|
+
YmFkZmM3MTE3ODc5Mzk2OTYxZTY0NTQwYjY0NjQwNzFjODY5NmY2MDE2MDFj
|
15
|
+
ODY0NWYxMzNmMTAzY2FkYjU5YzY3YTg2ODhmNjhhODFlYzc5ZjA=
|
data/CHANGELOG.md
CHANGED
@@ -1,100 +1,104 @@
|
|
1
|
-
# 1.1.
|
2
|
-
|
3
|
-
- Fix
|
4
|
-
|
5
|
-
# 1.1.
|
6
|
-
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
-
|
23
|
-
|
24
|
-
# 1.0.
|
25
|
-
|
26
|
-
- Fix: Issue
|
27
|
-
|
28
|
-
# 1.0.
|
29
|
-
|
30
|
-
-
|
31
|
-
|
32
|
-
# 1.0.
|
33
|
-
|
34
|
-
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
-
|
40
|
-
|
41
|
-
# 1.0.
|
42
|
-
|
43
|
-
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
-
|
49
|
-
|
50
|
-
# 1.0.
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
- Add
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
- LinkThumbnailer::Object
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
- LinkThumbnailer::
|
95
|
-
- LinkThumbnailer::
|
96
|
-
- LinkThumbnailer::
|
97
|
-
- LinkThumbnailer::
|
98
|
-
- LinkThumbnailer::
|
99
|
-
- LinkThumbnailer
|
100
|
-
- LinkThumbnailer
|
1
|
+
# 1.1.2
|
2
|
+
|
3
|
+
- Fix issue with FastImage URLs [https://github.com/gottfrois/link_thumbnailer/pull/31](https://github.com/gottfrois/link_thumbnailer/pull/31)
|
4
|
+
|
5
|
+
# 1.1.1
|
6
|
+
|
7
|
+
- Fix route helper not working under rails 4.
|
8
|
+
|
9
|
+
# 1.1.0
|
10
|
+
|
11
|
+
- Replace RMagick by [FastImage](https://github.com/sdsykes/fastimage)
|
12
|
+
- Rename `rmagick_attributes` config into `image_attributes`
|
13
|
+
|
14
|
+
# 1.0.9
|
15
|
+
|
16
|
+
- Fix issue when Location header used a relative path instead of an absolute path
|
17
|
+
- Update gemfile to be more flexible when using Hashie gem
|
18
|
+
|
19
|
+
# 1.0.8
|
20
|
+
|
21
|
+
- Thanks to [juriglx](https://github.com/juriglx), support for canonical urls
|
22
|
+
- Bug fixes
|
23
|
+
|
24
|
+
# 1.0.7
|
25
|
+
|
26
|
+
- Fix: Issue with preview controller
|
27
|
+
|
28
|
+
# 1.0.6
|
29
|
+
|
30
|
+
- Fix: Issue when setting `strict` option. Always returning OG representation.
|
31
|
+
|
32
|
+
# 1.0.5
|
33
|
+
|
34
|
+
- Thanks to [phlegx](https://github.com/phlegx), support for timeout http connection through configurations.
|
35
|
+
|
36
|
+
# 1.0.4
|
37
|
+
|
38
|
+
- Fix issue #7: nil img was returned when exception is raised. Now skiping nil images in results.
|
39
|
+
- Thanks to [phlegx](https://github.com/phlegx), support for SSL and User Agent customization through configurations.
|
40
|
+
|
41
|
+
# 1.0.3
|
42
|
+
|
43
|
+
- Fix issue #5: Url was incorect in case of HTTP Redirections.
|
44
|
+
|
45
|
+
# 1.0.2
|
46
|
+
|
47
|
+
- Feature: User can now set options at runtime by passing valid options to ```generate``` method
|
48
|
+
- Bug fix when doing ```rails g link_thumbnailer:install``` by explicitly specifying the scope of Rails
|
49
|
+
|
50
|
+
# 1.0.1
|
51
|
+
|
52
|
+
- Refactor LinkThumbnailer#generate method to have a cleaner code
|
53
|
+
|
54
|
+
# 1.0.0
|
55
|
+
|
56
|
+
- Update readme
|
57
|
+
- Add PreviewController for easy integration with user's app
|
58
|
+
- Add link_thumbnailer routes for easy integration with user's app
|
59
|
+
- Refactor some code
|
60
|
+
- Change 'to_a' method to 'to_hash' in object model
|
61
|
+
|
62
|
+
# 0.0.6
|
63
|
+
|
64
|
+
- Update readme
|
65
|
+
- Add `to_a` to WebImage class
|
66
|
+
- Refactor `to_json` for WebImage class
|
67
|
+
- Add specs corresponding
|
68
|
+
|
69
|
+
# 0.0.5
|
70
|
+
|
71
|
+
- Bug fix
|
72
|
+
- Remove `require 'rails'` from spec_helper.rb
|
73
|
+
- Remove rails dependences (blank? method) in code
|
74
|
+
- Spec fix
|
75
|
+
|
76
|
+
# 0.0.4
|
77
|
+
|
78
|
+
- Add specs for almost all classes
|
79
|
+
- Add a method `to_json` for WebImage class to be able to get a usable array of images' attributes
|
80
|
+
|
81
|
+
# 0.0.3
|
82
|
+
|
83
|
+
- Add specs for LinkThumbnailer class
|
84
|
+
- Refactor config system, now using dedicated configuration class
|
85
|
+
|
86
|
+
# 0.0.2
|
87
|
+
|
88
|
+
- Added Rspec
|
89
|
+
- Bug fixes:
|
90
|
+
- Now checking if attribute is blank for LinkThumbnailer::Object.valid? method
|
91
|
+
|
92
|
+
# 0.0.1
|
93
|
+
|
94
|
+
- LinkThumbnailer::Object
|
95
|
+
- LinkThumbnailer::Doc
|
96
|
+
- LinkThumbnailer::DocParser
|
97
|
+
- LinkThumbnailer::Fetcher
|
98
|
+
- LinkThumbnailer::ImgComparator
|
99
|
+
- LinkThumbnailer::ImgParser
|
100
|
+
- LinkThumbnailer::ImgUrlFilter
|
101
|
+
- LinkThumbnailer::Opengraph
|
102
|
+
- LinkThumbnailer::WebImage
|
103
|
+
- LinkThumbnailer.configure
|
104
|
+
- LinkThumbnailer.generate
|
data/LICENSE
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2012 Pierre-Louis Gottfrois
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
1
|
+
Copyright (c) 2012 Pierre-Louis Gottfrois
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
22
|
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,184 +1,184 @@
|
|
1
|
-
# LinkThumbnailer
|
2
|
-
|
3
|
-
[![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
|
4
|
-
[![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
|
5
|
-
[![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
|
6
|
-
|
7
|
-
Ruby 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.
|
8
|
-
|
9
|
-
Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
|
10
|
-
|
11
|
-
## Installation
|
12
|
-
|
13
|
-
Add this line to your application's Gemfile:
|
14
|
-
|
15
|
-
gem 'link_thumbnailer'
|
16
|
-
|
17
|
-
And then execute:
|
18
|
-
|
19
|
-
$ bundle
|
20
|
-
|
21
|
-
Or install it yourself as:
|
22
|
-
|
23
|
-
$ gem install link_thumbnailer
|
24
|
-
|
25
|
-
Run:
|
26
|
-
|
27
|
-
$ rails g link_thumbnailer:install
|
28
|
-
|
29
|
-
This will add `link_thumbnailer.rb` to `config/initializers/`. See [#Configuration](https://github.com/gottfrois/link_thumbnailer#configuration) for more details.
|
30
|
-
|
31
|
-
## Usage
|
32
|
-
|
33
|
-
Run `irb` and require the gem:
|
34
|
-
|
35
|
-
require 'rails'
|
36
|
-
=> true
|
37
|
-
|
38
|
-
require 'link_thumbnailer'
|
39
|
-
=> true
|
40
|
-
|
41
|
-
This gem can handle [Opengraph](http://ogp.me/) protocol. Here is an example with such a website:
|
42
|
-
|
43
|
-
object = LinkThumbnailer.generate('http://zerply.com')
|
44
|
-
=> #<LinkThumbnailer::Object description="Go beyond the résumé - showcase your work and your talent" image="http://zerply.com/img/front/facebook_icon_green.png" images=["http://zerply.com/img/front/facebook_icon_green.png"] site_name="zerply.com" title="Join Me on Zerply" url="http://zerply.com">
|
45
|
-
|
46
|
-
object.title?
|
47
|
-
=> true
|
48
|
-
object.title
|
49
|
-
=> "Join Me on Zerply"
|
50
|
-
|
51
|
-
object.url?
|
52
|
-
=> true
|
53
|
-
object.url
|
54
|
-
=> "http://zerply.com"
|
55
|
-
|
56
|
-
object.foo?
|
57
|
-
=> false
|
58
|
-
object.foo
|
59
|
-
=> nil
|
60
|
-
|
61
|
-
Now with a regular website with no particular protocol:
|
62
|
-
|
63
|
-
object = LinkThumbnailer.generate('http://foo.com')
|
64
|
-
=> #<LinkThumbnailer::Object description=nil images=[[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb] scene=0] title="Foo.com" url="http://foo.com">
|
65
|
-
|
66
|
-
object.title
|
67
|
-
=> "Foo.com"
|
68
|
-
|
69
|
-
object.images
|
70
|
-
=> [[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb]
|
71
|
-
scene=0]
|
72
|
-
|
73
|
-
object.images.first.source_url
|
74
|
-
=> #<URI::HTTP:0x007ff7a923ef58 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>
|
75
|
-
|
76
|
-
object.to_hash
|
77
|
-
=> {"url"=>"http://foo.com", "images"=>[{:source_url=>"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg", :mime_type=>"image/jpeg", :rows=>200, :filesize=>46501, :number_colors=>9490}], "title"=>"Foo.com", "description"=>nil}
|
78
|
-
|
79
|
-
object.to_json
|
80
|
-
=> "{\"url\":\"http://foo.com\",\"images\":[{\"source_url\":\"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg\",\"mime_type\":\"image/jpeg\",\"rows\":200,\"filesize\":46501,\"number_colors\":9490}],\"title\":\"Foo.com\",\"description\":null}"
|
81
|
-
|
82
|
-
You can check whether this object is valid or not (set mandatory attributes in the initializer, defaults are `[url, title, images]`)
|
83
|
-
|
84
|
-
object.valid?
|
85
|
-
=> true
|
86
|
-
|
87
|
-
You also can set options at runtime:
|
88
|
-
|
89
|
-
object = LinkThumbnailer.generate('http://foo.com', top: 10, limit: 20, redirect_limit: 5)
|
90
|
-
|
91
|
-
## Preview Controller
|
92
|
-
|
93
|
-
For an easy integration into your application, use the builtin `PreviewController`.
|
94
|
-
|
95
|
-
Take a look at the demo application [here](https://github.com/gottfrois/link_thumbnailer_demo).
|
96
|
-
|
97
|
-
Basically, all you have to do in your view is something like this:
|
98
|
-
|
99
|
-
<%= form_tag '/link/preview', method: :post, remote: true do %>
|
100
|
-
<%= text_field_tag :url %>
|
101
|
-
<%= submit_tag 'Preview' %>
|
102
|
-
<% end %>
|
103
|
-
|
104
|
-
Don't forget to add this anywhere in your `routes.rb` file:
|
105
|
-
|
106
|
-
use_link_thumbnailer
|
107
|
-
|
108
|
-
Note: You won't have to bother with this if you did run the installer using:
|
109
|
-
|
110
|
-
$ rails g link_thumbnailer:install
|
111
|
-
|
112
|
-
The `PreviewController` will automatically respond to json calls, returning json version of the preview object. Just like in the IRB console above.
|
113
|
-
|
114
|
-
## Configuration
|
115
|
-
|
116
|
-
In `config/initializers/link_thumbnailer.rb`
|
117
|
-
|
118
|
-
LinkThumbnailer.configure do |config|
|
119
|
-
# Set mandatory attributes require for the website to be valid.
|
120
|
-
# You can set `strict` to false if you want to skip this validation.
|
121
|
-
# config.mandatory_attributes = %w(url title image)
|
122
|
-
|
123
|
-
# Whether you want to validate given website against mandatory attributes or not.
|
124
|
-
# config.strict = true
|
125
|
-
|
126
|
-
# Numbers of redirects before raising an exception when trying to parse given url.
|
127
|
-
# config.redirect_limit = 3
|
128
|
-
|
129
|
-
# List of blacklisted urls you want to skip when searching for images.
|
130
|
-
# config.blacklist_urls = [
|
131
|
-
# %r{^http://ad\.doubleclick\.net/},
|
132
|
-
# %r{^http://b\.scorecardresearch\.com/},
|
133
|
-
# %r{^http://pixel\.quantserve\.com/},
|
134
|
-
# %r{^http://s7\.addthis\.com/}
|
135
|
-
# ]
|
136
|
-
|
137
|
-
# Fetch 10 images maximum.
|
138
|
-
# config.limit = 10
|
139
|
-
|
140
|
-
# Return top 5 images only.
|
141
|
-
# config.top = 5
|
142
|
-
|
143
|
-
# Set user agent
|
144
|
-
# config.user_agent = 'linkthumbnailer'
|
145
|
-
|
146
|
-
# Enable or disable SSL verification
|
147
|
-
# config.verify_ssl = true
|
148
|
-
|
149
|
-
# HTTP open_timeout: The amount of time in seconds to wait for a connection to be opened.
|
150
|
-
# config.http_timeout = 5
|
151
|
-
end
|
152
|
-
|
153
|
-
## Features
|
154
|
-
|
155
|
-
Implemented:
|
156
|
-
|
157
|
-
- Implements [OpenGraph](http://ogp.me/) protocol.
|
158
|
-
- Find images and sort them according to how well they represent what the page is about (includes absolute images).
|
159
|
-
- Sort images based on their size and color.
|
160
|
-
- Blacklist some well known advertisings image urls.
|
161
|
-
- Routes and Controllers to handle preview generation
|
162
|
-
|
163
|
-
Coming soon:
|
164
|
-
|
165
|
-
- Use the gem [ruby-readability](https://github.com/iterationlabs/ruby-readability) to parse images and website information
|
166
|
-
- Cache results on filesystem
|
167
|
-
|
168
|
-
## Contributing
|
169
|
-
|
170
|
-
1. Fork it
|
171
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
172
|
-
3. Run the specs (`bundle exec rspec spec`)
|
173
|
-
4. Commit your changes (`git commit -am 'Added some feature'`)
|
174
|
-
5. Push to the branch (`git push origin my-new-feature`)
|
175
|
-
6. Create new Pull Request
|
176
|
-
|
177
|
-
## Contributors
|
178
|
-
|
179
|
-
- [phlegx](https://github.com/phlegx)
|
180
|
-
- [juriglx](https://github.com/juriglx)
|
181
|
-
|
182
|
-
|
183
|
-
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gottfrois/link_thumbnailer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
184
|
-
|
1
|
+
# LinkThumbnailer
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/gottfrois/link_thumbnailer.png)](https://codeclimate.com/github/gottfrois/link_thumbnailer)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/gottfrois/link_thumbnailer/badge.png?branch=master)](https://coveralls.io/r/gottfrois/link_thumbnailer?branch=master)
|
5
|
+
[![Build Status](https://travis-ci.org/gottfrois/link_thumbnailer.png?branch=master)](https://travis-ci.org/gottfrois/link_thumbnailer)
|
6
|
+
|
7
|
+
Ruby 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.
|
8
|
+
|
9
|
+
Demo Application is [here](http://link-thumbnailer-demo.herokuapp.com/) !
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
gem 'link_thumbnailer'
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install link_thumbnailer
|
24
|
+
|
25
|
+
Run:
|
26
|
+
|
27
|
+
$ rails g link_thumbnailer:install
|
28
|
+
|
29
|
+
This will add `link_thumbnailer.rb` to `config/initializers/`. See [#Configuration](https://github.com/gottfrois/link_thumbnailer#configuration) for more details.
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
Run `irb` and require the gem:
|
34
|
+
|
35
|
+
require 'rails'
|
36
|
+
=> true
|
37
|
+
|
38
|
+
require 'link_thumbnailer'
|
39
|
+
=> true
|
40
|
+
|
41
|
+
This gem can handle [Opengraph](http://ogp.me/) protocol. Here is an example with such a website:
|
42
|
+
|
43
|
+
object = LinkThumbnailer.generate('http://zerply.com')
|
44
|
+
=> #<LinkThumbnailer::Object description="Go beyond the résumé - showcase your work and your talent" image="http://zerply.com/img/front/facebook_icon_green.png" images=["http://zerply.com/img/front/facebook_icon_green.png"] site_name="zerply.com" title="Join Me on Zerply" url="http://zerply.com">
|
45
|
+
|
46
|
+
object.title?
|
47
|
+
=> true
|
48
|
+
object.title
|
49
|
+
=> "Join Me on Zerply"
|
50
|
+
|
51
|
+
object.url?
|
52
|
+
=> true
|
53
|
+
object.url
|
54
|
+
=> "http://zerply.com"
|
55
|
+
|
56
|
+
object.foo?
|
57
|
+
=> false
|
58
|
+
object.foo
|
59
|
+
=> nil
|
60
|
+
|
61
|
+
Now with a regular website with no particular protocol:
|
62
|
+
|
63
|
+
object = LinkThumbnailer.generate('http://foo.com')
|
64
|
+
=> #<LinkThumbnailer::Object description=nil images=[[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb] scene=0] title="Foo.com" url="http://foo.com">
|
65
|
+
|
66
|
+
object.title
|
67
|
+
=> "Foo.com"
|
68
|
+
|
69
|
+
object.images
|
70
|
+
=> [[ JPEG 750x200 750x200+0+0 DirectClass 8-bit 45kb]
|
71
|
+
scene=0]
|
72
|
+
|
73
|
+
object.images.first.source_url
|
74
|
+
=> #<URI::HTTP:0x007ff7a923ef58 URL:http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg>
|
75
|
+
|
76
|
+
object.to_hash
|
77
|
+
=> {"url"=>"http://foo.com", "images"=>[{:source_url=>"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg", :mime_type=>"image/jpeg", :rows=>200, :filesize=>46501, :number_colors=>9490}], "title"=>"Foo.com", "description"=>nil}
|
78
|
+
|
79
|
+
object.to_json
|
80
|
+
=> "{\"url\":\"http://foo.com\",\"images\":[{\"source_url\":\"http://foo.com/media/BAhbB1sHOgZmSSItMjAxMi8wNC8yNi8yMC8xMS80OS80MjYvY29yZG92YWJlYWNoLmpwZwY6BkVUWwg6BnA6CnRodW1iSSINNzUweDIwMCMGOwZU/cordovabeach.jpg\",\"mime_type\":\"image/jpeg\",\"rows\":200,\"filesize\":46501,\"number_colors\":9490}],\"title\":\"Foo.com\",\"description\":null}"
|
81
|
+
|
82
|
+
You can check whether this object is valid or not (set mandatory attributes in the initializer, defaults are `[url, title, images]`)
|
83
|
+
|
84
|
+
object.valid?
|
85
|
+
=> true
|
86
|
+
|
87
|
+
You also can set options at runtime:
|
88
|
+
|
89
|
+
object = LinkThumbnailer.generate('http://foo.com', top: 10, limit: 20, redirect_limit: 5)
|
90
|
+
|
91
|
+
## Preview Controller
|
92
|
+
|
93
|
+
For an easy integration into your application, use the builtin `PreviewController`.
|
94
|
+
|
95
|
+
Take a look at the demo application [here](https://github.com/gottfrois/link_thumbnailer_demo).
|
96
|
+
|
97
|
+
Basically, all you have to do in your view is something like this:
|
98
|
+
|
99
|
+
<%= form_tag '/link/preview', method: :post, remote: true do %>
|
100
|
+
<%= text_field_tag :url %>
|
101
|
+
<%= submit_tag 'Preview' %>
|
102
|
+
<% end %>
|
103
|
+
|
104
|
+
Don't forget to add this anywhere in your `routes.rb` file:
|
105
|
+
|
106
|
+
use_link_thumbnailer
|
107
|
+
|
108
|
+
Note: You won't have to bother with this if you did run the installer using:
|
109
|
+
|
110
|
+
$ rails g link_thumbnailer:install
|
111
|
+
|
112
|
+
The `PreviewController` will automatically respond to json calls, returning json version of the preview object. Just like in the IRB console above.
|
113
|
+
|
114
|
+
## Configuration
|
115
|
+
|
116
|
+
In `config/initializers/link_thumbnailer.rb`
|
117
|
+
|
118
|
+
LinkThumbnailer.configure do |config|
|
119
|
+
# Set mandatory attributes require for the website to be valid.
|
120
|
+
# You can set `strict` to false if you want to skip this validation.
|
121
|
+
# config.mandatory_attributes = %w(url title image)
|
122
|
+
|
123
|
+
# Whether you want to validate given website against mandatory attributes or not.
|
124
|
+
# config.strict = true
|
125
|
+
|
126
|
+
# Numbers of redirects before raising an exception when trying to parse given url.
|
127
|
+
# config.redirect_limit = 3
|
128
|
+
|
129
|
+
# List of blacklisted urls you want to skip when searching for images.
|
130
|
+
# config.blacklist_urls = [
|
131
|
+
# %r{^http://ad\.doubleclick\.net/},
|
132
|
+
# %r{^http://b\.scorecardresearch\.com/},
|
133
|
+
# %r{^http://pixel\.quantserve\.com/},
|
134
|
+
# %r{^http://s7\.addthis\.com/}
|
135
|
+
# ]
|
136
|
+
|
137
|
+
# Fetch 10 images maximum.
|
138
|
+
# config.limit = 10
|
139
|
+
|
140
|
+
# Return top 5 images only.
|
141
|
+
# config.top = 5
|
142
|
+
|
143
|
+
# Set user agent
|
144
|
+
# config.user_agent = 'linkthumbnailer'
|
145
|
+
|
146
|
+
# Enable or disable SSL verification
|
147
|
+
# config.verify_ssl = true
|
148
|
+
|
149
|
+
# HTTP open_timeout: The amount of time in seconds to wait for a connection to be opened.
|
150
|
+
# config.http_timeout = 5
|
151
|
+
end
|
152
|
+
|
153
|
+
## Features
|
154
|
+
|
155
|
+
Implemented:
|
156
|
+
|
157
|
+
- Implements [OpenGraph](http://ogp.me/) protocol.
|
158
|
+
- Find images and sort them according to how well they represent what the page is about (includes absolute images).
|
159
|
+
- Sort images based on their size and color.
|
160
|
+
- Blacklist some well known advertisings image urls.
|
161
|
+
- Routes and Controllers to handle preview generation
|
162
|
+
|
163
|
+
Coming soon:
|
164
|
+
|
165
|
+
- Use the gem [ruby-readability](https://github.com/iterationlabs/ruby-readability) to parse images and website information
|
166
|
+
- Cache results on filesystem
|
167
|
+
|
168
|
+
## Contributing
|
169
|
+
|
170
|
+
1. Fork it
|
171
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
172
|
+
3. Run the specs (`bundle exec rspec spec`)
|
173
|
+
4. Commit your changes (`git commit -am 'Added some feature'`)
|
174
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
175
|
+
6. Create new Pull Request
|
176
|
+
|
177
|
+
## Contributors
|
178
|
+
|
179
|
+
- [phlegx](https://github.com/phlegx)
|
180
|
+
- [juriglx](https://github.com/juriglx)
|
181
|
+
|
182
|
+
|
183
|
+
[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/gottfrois/link_thumbnailer/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
|
184
|
+
|