thumbnailer 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/thumbnailer.rb +70 -2
- metadata +2 -2
data/lib/thumbnailer.rb
CHANGED
|
@@ -34,9 +34,21 @@ require 'exifr'
|
|
|
34
34
|
# f = File.new('happytree_t.gif', 'w')
|
|
35
35
|
# f.puts ThumbNailer.box_with_background('happytree.jpg', 125, 0.8, 0.2, 0.7)
|
|
36
36
|
# f.close
|
|
37
|
+
#
|
|
38
|
+
# A few extra function that I have found useful have been added to the
|
|
39
|
+
# package just so everything is in one place.
|
|
40
|
+
#
|
|
41
|
+
# f = File.new('happytree_t.gif', 'w')
|
|
42
|
+
# f.puts ThumbNailer.max_width('happytree.jpg', 125)
|
|
43
|
+
# f.close
|
|
44
|
+
#
|
|
45
|
+
# This will scale the image so that it is no wider than +size+ whilest
|
|
46
|
+
# maintaining the aspect ratio. There is also max_height to scale the
|
|
47
|
+
# image so that it is no taller than +size+ and max_either to scale the
|
|
48
|
+
# image if either width or height is larger than +size+.
|
|
37
49
|
|
|
38
50
|
class ThumbNailer
|
|
39
|
-
VERSION = '1.
|
|
51
|
+
VERSION = '1.3.0'
|
|
40
52
|
|
|
41
53
|
# The default colour, an impure black to be used for
|
|
42
54
|
# transparency or background
|
|
@@ -77,7 +89,7 @@ class ThumbNailer
|
|
|
77
89
|
# If the image is smaller than the box then it will be
|
|
78
90
|
# centered within the box as is.
|
|
79
91
|
def self.box_with_background(source, size, r = @@r, g = @@g, b = @@b)
|
|
80
|
-
image =
|
|
92
|
+
image = GD2::Image.import(source)
|
|
81
93
|
|
|
82
94
|
dstX, dstY, dstW, dstH, image = resize_source(image, size)
|
|
83
95
|
|
|
@@ -92,6 +104,62 @@ class ThumbNailer
|
|
|
92
104
|
return create_output(thumbnail, source)
|
|
93
105
|
end
|
|
94
106
|
|
|
107
|
+
# Scale the source image so that it is no wider than +size+
|
|
108
|
+
# or return the image as is if it is already +size+ or smaller
|
|
109
|
+
def self.max_width(source, size)
|
|
110
|
+
image = GD2::Image.import(source)
|
|
111
|
+
|
|
112
|
+
if image.width > size
|
|
113
|
+
scale = size.to_f / image.width.to_f
|
|
114
|
+
new_width = image.width.to_f * scale
|
|
115
|
+
new_height = image.height.to_f * scale
|
|
116
|
+
|
|
117
|
+
image.resize!(new_width, new_height, true)
|
|
118
|
+
else
|
|
119
|
+
# do nothing, return as is
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
return create_output(image, source)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Scale the source image so that it is no higher than +size+
|
|
126
|
+
# or return the image as is if it is already +size+ or smaller
|
|
127
|
+
def self.max_height(source, size)
|
|
128
|
+
image = GD2::Image.import(source)
|
|
129
|
+
|
|
130
|
+
if image.height > size
|
|
131
|
+
scale = size.to_f / image.height.to_f
|
|
132
|
+
new_width = image.width.to_f * scale
|
|
133
|
+
new_height = image.height.to_f * scale
|
|
134
|
+
|
|
135
|
+
image.resize!(new_width, new_height, true)
|
|
136
|
+
else
|
|
137
|
+
# do nothing, return as is
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
return create_output(image, source)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# Scale the source image so that it is no wider or higher than
|
|
144
|
+
# +size+ or return the image as is if it is already +size+ or smaller
|
|
145
|
+
def self.max_either(source, size)
|
|
146
|
+
image = GD2::Image.import(source)
|
|
147
|
+
|
|
148
|
+
max = image.width > image.height ? image.width : image.height
|
|
149
|
+
|
|
150
|
+
if max > size
|
|
151
|
+
scale = size.to_f / max.to_f
|
|
152
|
+
new_width = image.width.to_f * scale
|
|
153
|
+
new_height = image.height.to_f * scale
|
|
154
|
+
|
|
155
|
+
image.resize!(new_width, new_height, true)
|
|
156
|
+
else
|
|
157
|
+
# do nothing, return as is
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
return create_output(image, source)
|
|
161
|
+
end
|
|
162
|
+
|
|
95
163
|
# Change the output type to +png+ (default)
|
|
96
164
|
def self.output_png
|
|
97
165
|
@@OUTPUT_TYPE = 'png'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: thumbnailer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Hickman
|
|
@@ -9,7 +9,7 @@ autorequire:
|
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
11
|
|
|
12
|
-
date:
|
|
12
|
+
date: 2009-01-08 00:00:00 +00:00
|
|
13
13
|
default_executable:
|
|
14
14
|
dependencies: []
|
|
15
15
|
|