image_proc 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 1.0.3 / 2009-01-09
2
+
3
+ * Ensure the destination path is always returned
4
+
1
5
  === 1.0.2 / 2009-01-09
2
6
 
3
7
  * Allow nil keys in ImageProc.resize() options and just scrub them.
data/lib/image_proc.rb CHANGED
@@ -9,7 +9,7 @@ require 'open3'
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 = '1.0.2'
12
+ VERSION = '1.0.3'
13
13
 
14
14
  class Error < RuntimeError; end
15
15
  class MissingInput < Error; end
@@ -18,6 +18,7 @@ class ImageProc
18
18
  class NoOverwrites < Error; end
19
19
  class FormatUnsupported < Error; end
20
20
  class InvalidOptions < Error; end
21
+ class MissingOutput < Error; end
21
22
 
22
23
  HARMLESS = []
23
24
  class << self
@@ -61,18 +62,27 @@ class ImageProc
61
62
  end
62
63
  end
63
64
 
64
- # Resizes with specific options passed as a hash, and return the destination path to the resized image
65
+ def resize_with_geom_string(from_path, to_path, str) #:nodoc:
66
+ w, h = opts.scan(/^\d+x\d+$/).to_a.flatten
67
+ resize(from_path, to_path, :width => w, :height => h)
68
+ result_w, result_h = get_bounds(to_path)
69
+ [to_path, result_w, result_h]
70
+ end
71
+
72
+ # Resizes with specific options passed as a hash.
73
+ # It returns the destination path to the resized image. If you need to know the resulting size
74
+ # of the image just call a ImageProc.get_bounds on the result path
75
+ #
65
76
  # ImageProc.resize "/tmp/foo.jpg", "bla.jpg", :width => 120, :height => 30
66
77
  def resize(from_path, to_path, opts = {})
67
78
  if opts.is_a?(String)
68
79
  STDERR.puts "String argument to resize() is really deprecated"
69
- w, h = opts.scan(/^\d+x\d+$/).to_a.flatten
70
- return resize(from_path, to_path, :width => w, :height => h)
80
+ resize_with_geom_string(from_path, to_path, opts)
71
81
  end
72
82
 
73
83
  remove_nil_values!(opts)
84
+
74
85
  raise InvalidOptions, "The only allowed options are :width, :height and :fill" if (opts.keys - [:width, :height, :fill]).any?
75
- raise InvalidOptions, "Pass width, height or both" unless (opts.keys & [:width, :height]).any?
76
86
 
77
87
  if opts[:width] && opts[:height] && opts[:fill]
78
88
  resize_fit_fill(from_path, to_path, opts[:width], opts[:height])
@@ -83,9 +93,11 @@ class ImageProc
83
93
  elsif opts[:height]
84
94
  resize_fit_height(from_path, to_path, opts[:height])
85
95
  else
86
- raise "This should never happen"
96
+ raise InvalidOptions, "Pass width, height or both"
87
97
  end
88
- to_path
98
+ raise MissingOutput unless File.exist?(to_path)
99
+
100
+ return to_path
89
101
  end
90
102
 
91
103
  # Resize an image fitting the biggest side of it to the side of a square. A must for thumbs.
@@ -297,6 +309,7 @@ ImageProc.keep_quiet do
297
309
  # -Z pixelsWH --resampleHeightWidthMax pixelsWH
298
310
  FORMAT_MAP = { ".tif" => "tiff", ".png" => "png", ".tif" => "tiff", ".gif" => "gif" }
299
311
  HARMLESS = [/XRefStm encountered but/, /CGColor/]
312
+
300
313
  def process_exact
301
314
  fmt = detect_source_format
302
315
  wrap_stderr("sips -s format #{fmt} --resampleHeightWidth #{@target_h} #{@target_w} #{@source} --out '#{@dest}'")
@@ -20,7 +20,8 @@ class TestQuickProcessWithOptions < Test::Unit::TestCase
20
20
  opts = {:height=>75, :fill=>true}
21
21
  begin
22
22
  assert_nothing_raised do
23
- path, w, h = ImageProc.resize(source, dest, opts)
23
+ path = ImageProc.resize(source, dest, opts)
24
+ assert_equal dest, path
24
25
  end
25
26
  ensure
26
27
  File.unlink(dest) rescue nil
@@ -50,6 +51,7 @@ class TestQuickProcessWithOptions < Test::Unit::TestCase
50
51
  begin
51
52
  assert_nothing_raised do
52
53
  path = ImageProc.resize(source, dest, opts)
54
+ assert_equal dest, path
53
55
  end
54
56
  ensure
55
57
  File.unlink(dest) rescue nil
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: image_proc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.2
5
+ version: 1.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Julik