url2png 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -28,8 +28,9 @@ You can define the api version if you want to use an different version of the ur
28
28
  g
29
29
  Available versions:
30
30
 
31
- * v4 (default)
32
- * v6 (in beta, only for enabled users)
31
+ * v3
32
+ * v4
33
+ * v6 (default)
33
34
 
34
35
 
35
36
  ##### mode
@@ -65,6 +66,9 @@ Generate an image tag:
65
66
 
66
67
  To only get the image url:
67
68
 
69
+ url2png_image_url url, [options]
70
+
71
+ # alias (older version)
68
72
  site_image_url url, [options]
69
73
 
70
74
  Options differ by version!
@@ -80,7 +84,11 @@ default: no resizing
80
84
  url2png_image_tag 'http://www.zwartopwit.com',
81
85
  :thumbnail_max_width => 500,
82
86
  :thumbnail_max_height => 500
83
-
87
+
88
+ # alias for :thumbnail_...
89
+ :max_width => 500
90
+ :max_height => 500
91
+
84
92
 
85
93
  ##### Viewport
86
94
  Set viewport dimensions, adjust to your hearts content.<br>
@@ -118,17 +126,21 @@ Forces a fresh screenshot with each request, overwriting the previous copy.<br>
118
126
 
119
127
  url2png_image_tag 'http://www.zwartopwit.com',
120
128
  :force => true
129
+
130
+
131
+ ##### Size
132
+ Sets width and height attributes from the html \<img> tag.
133
+
134
+ url2png_image_tag 'http://www.zwartopwit.com',
135
+ :size => "800x600"
121
136
 
122
137
 
123
138
  ### Version 4
124
139
 
140
+ ##### Thumbnail
125
141
 
126
- ##### Size
127
142
  By default the size is set to 400 x 400 px.
128
-
129
- This is a proportion bounding box. Thumbnails will be resized to fit within this box.
130
-
131
- default: 'ORIGINAL'<br>
143
+ Proportions are constrained.
132
144
 
133
145
  examples:
134
146
 
@@ -137,8 +149,10 @@ examples:
137
149
 
138
150
  url2png_image_tag 'http://www.zwartopwit.com',
139
151
  :size => 'ORIGINAL'
152
+ ##### Size
153
+
154
+ This is a proportion bounding box. Almost the same as :thumbnail, but thumbnails will be resized to fit within this box. Width and height attribute of the html \<img> tag will be set.
140
155
 
141
- ##### Thumbnail (alias for :size)
142
156
 
143
157
  ##### Browser size
144
158
  Set the initial browser screen size.<br>
@@ -150,7 +164,6 @@ Set the initial browser screen size.<br>
150
164
  example:
151
165
 
152
166
  url2png_image_tag 'http://www.zwartopwit.com',
153
- :size => '300x200',
154
167
  :browser_size => '1024x2500'
155
168
 
156
169
  ##### Delay
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.0
1
+ 0.3.1
@@ -42,7 +42,7 @@ module Url2png
42
42
  end
43
43
 
44
44
  def api_version=api_version
45
- @api_version = api_version || 'v4'
45
+ @api_version = api_version || 'v6' # set default to latest open version
46
46
  end
47
47
 
48
48
  def api_version
@@ -2,9 +2,9 @@ module Url2png
2
2
  module Dimensions
3
3
 
4
4
  def self.parse options
5
- if Url2png.api_version == "v6"
6
- options[:size] ||= "#{options[:thumbnail_max_width]}x#{options[:thumbnail_max_height]}"
7
- end
5
+ # if Url2png.api_version == "v6"
6
+ # options[:size] ||= "#{options[:thumbnail_max_width]}x#{options[:thumbnail_max_height]}"
7
+ # end
8
8
 
9
9
  # distill image size
10
10
  size = (options[:size] || Url2png.default_size).split('x')
@@ -16,7 +16,7 @@ module Url2png
16
16
 
17
17
  # build image tag
18
18
  img = '<img'
19
- img << " src='#{ site_image_url(url, options) }'"
19
+ img << " src='#{ url2png_image_url(url, options) }'"
20
20
  img << " alt='#{ alt }'"
21
21
  img << " width='#{ dim[:width] }'" if options[:size]
22
22
  img << " height='#{ dim[:height] }'" if options[:size]
@@ -28,23 +28,9 @@ module Url2png
28
28
  end
29
29
 
30
30
 
31
- def check_options options, options_available
32
-
33
- # filter out unavailable options
34
- options = options.select do |key, value|
35
- if options_available.include? key
36
- true
37
- else
38
- # size is a special option, only usable in the gem
39
- homepage = "https://github.com/robinhoudmeyers/url2png-gem"
40
- raise "\"#{key}\" is not a valid option \nCheck the gem homepage for information about options: #{homepage}" unless key == :size
41
- end
42
- end
43
- end
44
-
45
31
  # --------------------------
46
32
  # only the url for the image
47
- def site_image_url url, options = {}
33
+ def url2png_image_url url, options = {}
48
34
  # parse size
49
35
  dim = Url2png::Dimensions.parse(options)
50
36
 
@@ -81,7 +67,6 @@ module Url2png
81
67
  else
82
68
  # build parameters portion of URL
83
69
  case Url2png.api_version
84
-
85
70
  when 'v6'
86
71
  ######
87
72
  # v6 #
@@ -89,7 +74,31 @@ module Url2png
89
74
  ######
90
75
 
91
76
  # check for unavailable options
77
+ options_alias = [:max_width, :max_height]
92
78
  options_available = [:force, :fullpage, :thumbnail_max_width, :thumbnail_max_height, :viewport]
79
+
80
+ # assign alias to valid option
81
+ options_alias.each do |key|
82
+ if options.key?(key)
83
+ case key
84
+ # when :size
85
+ # options[:thumbnail_max_width] = options[:size].split('x')[0] if options[:thumbnail_max_width].nil?
86
+ # options[:thumbnail_max_height] = options[:size].split('x')[1] if options[:thumbnail_max_height].nil?
87
+ when :max_width
88
+ options[:thumbnail_max_width] = options[key] if options[:thumbnail_max_width].nil?
89
+ options.delete(key)
90
+ when :max_height
91
+ options[:thumbnail_max_height] = options[key] if options[:thumbnail_max_height].nil?
92
+ options.delete(key)
93
+ end
94
+ end
95
+ end
96
+
97
+ # options_alias.each do |key|
98
+ # if options.include?(key) then options.delete(key) end
99
+ # end
100
+
101
+
93
102
  options = check_options(options, options_available)
94
103
 
95
104
  # add url to options query
@@ -105,9 +114,7 @@ module Url2png
105
114
  token = Url2png.token query_string
106
115
 
107
116
 
108
- "http://beta.url2png.com/v6/#{Url2png.api_key}/#{token}/png/?#{query_string}"
109
-
110
-
117
+ "http://beta.url2png.com/v6/#{Url2png.api_key}/#{token}/png/?#{query_string}"
111
118
 
112
119
  when 'v4'
113
120
  ######
@@ -127,7 +134,11 @@ module Url2png
127
134
 
128
135
  # build options portion of URL
129
136
  url_options = []
130
- url_options << "t#{ dim[:size] }" if dim[:size]
137
+
138
+ # set thumbnail
139
+ options[:thumbnail] ||= options[:size]
140
+
141
+ url_options << "t#{ options[:thumbnail] }"
131
142
  url_options << "s#{ options[:browser_size] }" if options[:browser_size]
132
143
  url_options << "d#{ options[:delay] }" if options[:delay]
133
144
  url_options << "FULL" if options[:fullscreen]
@@ -147,18 +158,18 @@ module Url2png
147
158
  ######
148
159
  # v3 #
149
160
  ######
150
-
161
+
151
162
  # http://api.url2png.com/v3/api_key/security_hash/bounds/url
152
-
163
+
153
164
  options_available = [:fullscreen, :size]
154
165
  options = check_options(options, options_available)
155
166
 
156
167
  # escape the url
157
168
  safe_url= CGI::escape(url)
158
-
169
+
159
170
  # generate token
160
171
  token = Url2png.token safe_url
161
-
172
+
162
173
  # custom size or default_size
163
174
  size = options[:size] || Url2png.default_size
164
175
 
@@ -179,14 +190,34 @@ module Url2png
179
190
  safe_url
180
191
  )
181
192
  end
193
+
182
194
  end
183
195
  end
184
-
196
+
197
+ def check_options options, options_available
198
+
199
+ # filter out unavailable options
200
+ options = options.select do |key, value|
201
+ if options_available.include? key
202
+ true
203
+ else
204
+ # size is a special option, only usable in the gem
205
+ homepage = "https://github.com/robinhoudmeyers/url2png-gem"
206
+ raise "#{options} \n \"#{key}\" is not a valid option \nCheck the gem homepage for information about options: #{homepage}" unless key == :size
207
+
208
+ end
209
+ end
210
+ end
211
+
185
212
  # -----
186
213
  # Alias
187
214
  def site_image_tag url, options = {}
188
215
  url2png_image_tag(url, options)
189
- end
216
+ end
217
+
218
+ def site_image_url url, options = {}
219
+ url2png_image_url(url, options)
220
+ end
190
221
  end
191
222
  end
192
223
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "url2png"
8
- s.version = "0.3.0"
8
+ s.version = "0.3.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["robinhoudmeyers", "wout fierens", "fuzzyalej", "ceritium", "lukemelia"]
12
- s.date = "2012-06-27"
12
+ s.date = "2012-08-14"
13
13
  s.description = "Generate screenshots from websites almost instantly at any preferred size using ruby and the url2png.com API"
14
14
  s.email = "houdmeyers@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: url2png
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,11 +13,11 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2012-06-27 00:00:00.000000000 Z
16
+ date: 2012-08-14 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: rspec
20
- requirement: &70092339600580 !ruby/object:Gem::Requirement
20
+ requirement: &70337114355240 !ruby/object:Gem::Requirement
21
21
  none: false
22
22
  requirements:
23
23
  - - ~>
@@ -25,10 +25,10 @@ dependencies:
25
25
  version: 2.6.0
26
26
  type: :development
27
27
  prerelease: false
28
- version_requirements: *70092339600580
28
+ version_requirements: *70337114355240
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: bundler
31
- requirement: &70092339599060 !ruby/object:Gem::Requirement
31
+ requirement: &70337114354700 !ruby/object:Gem::Requirement
32
32
  none: false
33
33
  requirements:
34
34
  - - ~>
@@ -36,10 +36,10 @@ dependencies:
36
36
  version: 1.1.3
37
37
  type: :development
38
38
  prerelease: false
39
- version_requirements: *70092339599060
39
+ version_requirements: *70337114354700
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: jeweler
42
- requirement: &70092339613580 !ruby/object:Gem::Requirement
42
+ requirement: &70337114354220 !ruby/object:Gem::Requirement
43
43
  none: false
44
44
  requirements:
45
45
  - - ~>
@@ -47,10 +47,10 @@ dependencies:
47
47
  version: 1.8.3
48
48
  type: :development
49
49
  prerelease: false
50
- version_requirements: *70092339613580
50
+ version_requirements: *70337114354220
51
51
  - !ruby/object:Gem::Dependency
52
52
  name: rcov
53
- requirement: &70092339611600 !ruby/object:Gem::Requirement
53
+ requirement: &70337114353720 !ruby/object:Gem::Requirement
54
54
  none: false
55
55
  requirements:
56
56
  - - ! '>='
@@ -58,10 +58,10 @@ dependencies:
58
58
  version: '0'
59
59
  type: :development
60
60
  prerelease: false
61
- version_requirements: *70092339611600
61
+ version_requirements: *70337114353720
62
62
  - !ruby/object:Gem::Dependency
63
63
  name: rspec
64
- requirement: &70092339606840 !ruby/object:Gem::Requirement
64
+ requirement: &70337114353200 !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>'
@@ -69,7 +69,7 @@ dependencies:
69
69
  version: 2.6.0
70
70
  type: :development
71
71
  prerelease: false
72
- version_requirements: *70092339606840
72
+ version_requirements: *70337114353200
73
73
  description: Generate screenshots from websites almost instantly at any preferred
74
74
  size using ruby and the url2png.com API
75
75
  email: houdmeyers@gmail.com
@@ -112,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
112
  version: '0'
113
113
  segments:
114
114
  - 0
115
- hash: -354415127866206290
115
+ hash: 1894113596075630694
116
116
  required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  none: false
118
118
  requirements: