image_proc 0.1.1 → 1.0.1
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/History.txt +5 -3
- data/README.txt +5 -0
- data/lib/image_proc.rb +20 -20
- data/test/resize_test_helper.rb +7 -6
- data/test/test_image_proc.rb +5 -5
- metadata +2 -2
data/History.txt
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
=== 1.0.1 / 2009-01-09
|
|
2
2
|
|
|
3
|
-
*
|
|
3
|
+
* Remove the old geometry string API
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
=== 0.1.1 / 2009-01-09
|
|
6
|
+
|
|
7
|
+
* Small updates to Hoe and other software rot prevention
|
|
6
8
|
|
|
7
|
-
=== 1.0
|
|
9
|
+
=== 0.1.0 / 2009-01-09
|
|
8
10
|
|
|
9
11
|
* 1 major enhancement
|
|
10
12
|
|
data/README.txt
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
* http://wiretap.rubyforge.org/image_proc
|
|
4
4
|
|
|
5
|
+
== SYNPOSIS
|
|
6
|
+
|
|
7
|
+
require "image_proc"
|
|
8
|
+
ImageProc.resize("/tmp/source_file.jpg", :width => 128, :height => 200, :fill => :true)
|
|
9
|
+
|
|
5
10
|
== DESCRIPTION:
|
|
6
11
|
|
|
7
12
|
A no-frills image resizer, with pluggable backends. No extra software required on OS X
|
data/lib/image_proc.rb
CHANGED
|
@@ -4,12 +4,12 @@ require 'open3'
|
|
|
4
4
|
# design. Sort of like the Processors in attachment_fu but less. Less.
|
|
5
5
|
#
|
|
6
6
|
# width, height = ImageProc.get_bounds("image.png")
|
|
7
|
-
# thumb_filename = ImageProc.resize("image.png", "thumb.png",
|
|
7
|
+
# thumb_filename = ImageProc.resize("image.png", "thumb.png", :width => 50. :height => 50)
|
|
8
8
|
#
|
|
9
9
|
# The whole idea is: a backend does not have to support cropping (we don't do it), it has only to be able to resize,
|
|
10
10
|
# and a backend should have 2 public methods. That's the game.
|
|
11
11
|
class ImageProc
|
|
12
|
-
VERSION = '0.1
|
|
12
|
+
VERSION = '1.0.1'
|
|
13
13
|
|
|
14
14
|
class Error < RuntimeError; end
|
|
15
15
|
class MissingInput < Error; end
|
|
@@ -41,12 +41,12 @@ class ImageProc
|
|
|
41
41
|
|
|
42
42
|
# Tries to detect the best engine available
|
|
43
43
|
def detect_engine
|
|
44
|
-
if
|
|
45
|
-
ImageProcSips
|
|
46
|
-
elsif (`which convert` =~ /^\// )
|
|
44
|
+
if (`which convert` =~ /^\// )
|
|
47
45
|
ImageProcConvert
|
|
46
|
+
elsif RUBY_PLATFORM =~ /darwin/i
|
|
47
|
+
ImageProcSips
|
|
48
48
|
else
|
|
49
|
-
raise "This system has no image processing facitilites that we can use"
|
|
49
|
+
raise "This system has no image processing facitilites that we can use. Time to compile RMagick or install a decent OS."
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -61,20 +61,13 @@ class ImageProc
|
|
|
61
61
|
end
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
#
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
resize_fit_both(from, to, to_width, to_height).shift
|
|
68
|
-
end
|
|
69
|
-
alias_method :process, :resize
|
|
70
|
-
|
|
71
|
-
# Resizes with specific options passed as a hash
|
|
72
|
-
# ImageProc.resize_with_options "/tmp/foo.jpg", "bla.jpg", :width => 120, :height => 30
|
|
73
|
-
def resize_with_options(from_path, to_path, opts = {})
|
|
64
|
+
# Resizes with specific options passed as a hash, and return the destination path to the resized image
|
|
65
|
+
# ImageProc.resize "/tmp/foo.jpg", "bla.jpg", :width => 120, :height => 30
|
|
66
|
+
def resize(from_path, to_path, opts = {})
|
|
74
67
|
# raise InvalidOptions,
|
|
75
68
|
# "The only allowed options are :width, :height and :fill" if (opts.keys - [:width, :height, :fill]).any?
|
|
76
|
-
raise InvalidOptions,
|
|
77
|
-
|
|
69
|
+
raise InvalidOptions, "Geometry string is no longer supported as argument for resize()" if opts.is_a?(String)
|
|
70
|
+
raise InvalidOptions, "Pass width, height or both" unless (opts.keys & [:width, :height]).any?
|
|
78
71
|
opts.each_pair { |k,v| raise InvalidOptions, "#{k.inspect} cannot be set to nil" if v.nil? }
|
|
79
72
|
|
|
80
73
|
if opts[:width] && opts[:height] && opts[:fill]
|
|
@@ -88,6 +81,7 @@ class ImageProc
|
|
|
88
81
|
else
|
|
89
82
|
raise "This should never happen"
|
|
90
83
|
end
|
|
84
|
+
to_path
|
|
91
85
|
end
|
|
92
86
|
|
|
93
87
|
# Resize an image fitting the biggest side of it to the side of a square. A must for thumbs.
|
|
@@ -186,13 +180,19 @@ class ImageProc
|
|
|
186
180
|
# It's recommended to clip the image which will be created with these bounds using CSS, as not all resizers support
|
|
187
181
|
# cropping - and besides it's just too many vars.
|
|
188
182
|
def fit_sizes_with_crop(bounds, opts)
|
|
189
|
-
|
|
183
|
+
force_keys!(opts, :width, :height)
|
|
190
184
|
scale = [opts[:width].to_f / bounds[0], opts[:height].to_f / bounds[1]].sort.pop
|
|
191
185
|
result = [bounds[0] * scale, bounds[1] * scale]
|
|
192
186
|
result.map{|e| e.round}
|
|
193
187
|
end
|
|
194
188
|
|
|
195
189
|
private
|
|
190
|
+
def force_keys!(in_hash, *keynames)
|
|
191
|
+
unless (in_hash.keys & keynames).length == keynames.length
|
|
192
|
+
raise Error, "This method requires #{keynames.join(', ')}"
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
196
|
def prevent_zeroes_in(floats)
|
|
197
197
|
floats.map!{|f| r = f.round.to_i; (r.zero? ? 1 : r) }
|
|
198
198
|
end
|
|
@@ -244,7 +244,7 @@ ImageProc.keep_quiet do
|
|
|
244
244
|
class ImageProcConvert < ImageProc
|
|
245
245
|
HARMLESS = [/unknown field with tag/]
|
|
246
246
|
def process_exact
|
|
247
|
-
wrap_stderr("convert -resize #{@target_w}x#{@target_h}! #{@source} #{@dest}")
|
|
247
|
+
wrap_stderr("convert -filter Gaussian -resize #{@target_w}x#{@target_h}! #{@source} #{@dest}")
|
|
248
248
|
end
|
|
249
249
|
|
|
250
250
|
def get_bounds(of)
|
data/test/resize_test_helper.rb
CHANGED
|
@@ -36,7 +36,8 @@ module ResizeTestHelper
|
|
|
36
36
|
|
|
37
37
|
def test_resize_raises_when_trying_to_overwrite
|
|
38
38
|
assert_raise(ImageProc::NoOverwrites) do
|
|
39
|
-
@processor.resize INPUTS + '/' + @landscapes[0], INPUTS + '/' + @portraits[0],
|
|
39
|
+
@processor.resize INPUTS + '/' + @landscapes[0], INPUTS + '/' + @portraits[0],
|
|
40
|
+
:width => 100, :height => 100
|
|
40
41
|
end
|
|
41
42
|
end
|
|
42
43
|
|
|
@@ -44,7 +45,8 @@ module ResizeTestHelper
|
|
|
44
45
|
missing_input = "/tmp/___imageproc_missing.jpg"
|
|
45
46
|
assert !File.exist?(missing_input)
|
|
46
47
|
assert_raise(ImageProc::MissingInput) do
|
|
47
|
-
@processor.resize missing_input, OUTPUTS + '/zeoutput.jpg',
|
|
48
|
+
@processor.resize missing_input, OUTPUTS + '/zeoutput.jpg',
|
|
49
|
+
:width => 100, :height => 100
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
@@ -54,7 +56,7 @@ module ResizeTestHelper
|
|
|
54
56
|
|
|
55
57
|
assert !File.exist?(File.dirname(missing_output))
|
|
56
58
|
assert_raise(ImageProc::NoDestinationDir) do
|
|
57
|
-
@processor.resize from, missing_output,
|
|
59
|
+
@processor.resize from, missing_output, :width => 100, :height => 100
|
|
58
60
|
end
|
|
59
61
|
end
|
|
60
62
|
|
|
@@ -147,7 +149,7 @@ module ResizeTestHelper
|
|
|
147
149
|
|
|
148
150
|
def test_resize_is_alias_for_fit_with_geometry_string
|
|
149
151
|
with_each_horizontal_path_and_name do | source, name |
|
|
150
|
-
assert_nothing_raised { @processor.resize(source, OUTPUTS + '/' + name,
|
|
152
|
+
assert_nothing_raised { @processor.resize(source, OUTPUTS + '/' + name, :width => 300, :height => 300) }
|
|
151
153
|
|
|
152
154
|
result_p = OUTPUTS + '/' + File.basename(source)
|
|
153
155
|
assert File.exist?(result_p), "#{result_p} should have been created"
|
|
@@ -156,8 +158,7 @@ module ResizeTestHelper
|
|
|
156
158
|
|
|
157
159
|
with_each_vertical_path_and_name do | source, name |
|
|
158
160
|
assert_nothing_raised do
|
|
159
|
-
path = @processor.resize(source, OUTPUTS + '/' + name,
|
|
160
|
-
assert_kind_of String, path, "ImageProc#resize is legacy so it should return the path and nothing else"
|
|
161
|
+
path = @processor.resize(source, OUTPUTS + '/' + name, :width => 300, :height => 300)
|
|
161
162
|
assert_equal OUTPUTS + '/' + File.basename(source), path, "The proc should return the path to the result"
|
|
162
163
|
end
|
|
163
164
|
|
data/test/test_image_proc.rb
CHANGED
|
@@ -19,7 +19,7 @@ class TestQuickProcessWithOptions < Test::Unit::TestCase
|
|
|
19
19
|
opts = {:height=>75, :fill=>true}
|
|
20
20
|
begin
|
|
21
21
|
assert_nothing_raised do
|
|
22
|
-
path, w, h = ImageProc.
|
|
22
|
+
path, w, h = ImageProc.resize(source, dest, opts)
|
|
23
23
|
end
|
|
24
24
|
ensure
|
|
25
25
|
File.unlink(dest) rescue nil
|
|
@@ -31,14 +31,14 @@ class TestQuickProcessWithOptions < Test::Unit::TestCase
|
|
|
31
31
|
source = File.dirname(__FILE__) + '/input/horizontal.jpg'
|
|
32
32
|
dest = File.dirname(__FILE__) + '/output/resized.jpg'
|
|
33
33
|
opts = {:too => 4, :doo => 10}
|
|
34
|
-
ImageProc.
|
|
34
|
+
ImageProc.resize(source, dest, opts)
|
|
35
35
|
end
|
|
36
36
|
|
|
37
37
|
assert_raise(ImageProc::InvalidOptions) do
|
|
38
38
|
source = File.dirname(__FILE__) + '/input/horizontal.jpg'
|
|
39
39
|
dest = File.dirname(__FILE__) + '/output/resized.jpg'
|
|
40
40
|
opts = {}
|
|
41
|
-
ImageProc.
|
|
41
|
+
ImageProc.resize(source, dest, opts)
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
end
|
|
@@ -63,13 +63,13 @@ if RUBY_PLATFORM =~ /darwin/i
|
|
|
63
63
|
|
|
64
64
|
def test_sips_does_not_grok_pngs
|
|
65
65
|
assert_raise(ImageProc::FormatUnsupported) do
|
|
66
|
-
@processor.resize(INPUTS + '/horizontal.gif', OUTPUTS + '/horizontal.gif',
|
|
66
|
+
@processor.resize(INPUTS + '/horizontal.gif', OUTPUTS + '/horizontal.gif', :width=> 100, :height => 100)
|
|
67
67
|
end
|
|
68
68
|
end
|
|
69
69
|
|
|
70
70
|
def test_sips_does_not_grok_gifs
|
|
71
71
|
assert_raise(ImageProc::FormatUnsupported) do
|
|
72
|
-
@processor.resize(INPUTS + '/horizontal.png', OUTPUTS + '/horizontal.png',
|
|
72
|
+
@processor.resize(INPUTS + '/horizontal.png', OUTPUTS + '/horizontal.png', :width=> 100, :height => 100)
|
|
73
73
|
end
|
|
74
74
|
end
|
|
75
75
|
|
metadata
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
name: image_proc
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease:
|
|
5
|
-
version: 0.1
|
|
5
|
+
version: 1.0.1
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
8
8
|
- Julik
|
|
@@ -10,7 +10,7 @@ autorequire:
|
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
12
|
|
|
13
|
-
date: 2011-
|
|
13
|
+
date: 2011-07-03 00:00:00 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: hoe
|