micro_magick 0.0.1 → 0.0.2

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/README.md CHANGED
@@ -45,13 +45,14 @@ In-place image edits through ```mogrify``` are not supported (yet).
45
45
 
46
46
  ### GraphicsMagick versus ImageMagick
47
47
 
48
+ *At least in my testing, GraphicsMagick blows ImageMagick out of the water.*
49
+
48
50
  In resizing a 2248x4000 image to 640x480:
49
- * GraphicsMagick takes 141 milliseconds. ImageMagick takes over 550 millis.
50
- * GraphicsMagick outputs a 37K JPG, ImageMagick outputs a 94K JPG, with no detectable visual differences.
51
51
 
52
- At least in my testing, GraphicsMagick blows ImageMagick out of the water.
52
+ * GraphicsMagick takes ~140 milliseconds. ImageMagick takes ~550 millis.
53
+ * GraphicsMagick outputs a 37K JPG, ImageMagick outputs a 94K JPG, with no detectable visual differences.
53
54
 
54
- Not only is it 4 times faster, it produces 2.5x smaller output with the same quality--WIN WIN.
55
+ Not only is GraphicsMagick 4 times faster, it produces 2.5x smaller output with the same quality--WIN WIN.
55
56
 
56
57
  ## Installation
57
58
 
@@ -6,15 +6,17 @@ module MicroMagick
6
6
  @args = [Shellwords.escape(input_file)]
7
7
  end
8
8
 
9
- def command
10
- ([MicroMagick.cmd_prefix, "convert", @pre_input] + @args).compact.join(" ")
11
- end
12
-
13
9
  def write(output_file)
14
10
  @args << Shellwords.escape(output_file)
15
- MicroMagick.exec command
11
+ cmd = build_command()
12
+ MicroMagick.exec(cmd)
13
+ @args = @args.first(1)
14
+ @pre_input = nil
15
+ cmd
16
16
  end
17
17
 
18
+ protected
19
+
18
20
  def method_missing(method, *args, &block)
19
21
  if @pre_input.nil? && [:geometry, :resize, :sample, :scale].include?(method)
20
22
  dimensions = args.first
@@ -33,5 +35,9 @@ module MicroMagick
33
35
  end
34
36
  @args += args.compact.collect { |ea| Shellwords.escape(ea.to_s) }
35
37
  end
38
+
39
+ def build_command
40
+ ([MicroMagick.cmd_prefix, "convert", @pre_input] + @args).compact.join(" ")
41
+ end
36
42
  end
37
43
  end
@@ -1,3 +1,3 @@
1
1
  module MicroMagick
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -31,16 +31,35 @@ class TestMicroMagick < Test::Unit::TestCase
31
31
  i.gravity("Center")
32
32
  i.crop("250x250")
33
33
  i.resize("128x128")
34
+ tmp = mktmpfile
35
+ assert !File.exist?(tmp)
36
+ command = i.write(tmp)
37
+ assert_equal command, "gm convert -size 128x128 test/640.jpg +profile \\* " +
38
+ "-quality 85 -gravity Center -crop 250x250 -resize 128x128 " +
39
+ Shellwords.escape(tmp)
40
+ assert File.exist?(tmp)
41
+
42
+ # make sure calling previous arguments don't leak into new calls:
43
+ i.resize("64x64")
44
+ command = i.write(tmp)
45
+ assert_equal command, "gm convert -size 64x64 test/640.jpg -resize 64x64 " +
46
+ Shellwords.escape(tmp)
47
+ end
48
+
49
+ def mktmpfile
34
50
  tmp = Tempfile.new('out.jpg')
35
51
  outfile = tmp.path
36
52
  tmp.close
37
53
  tmp.delete
38
- assert !File.exist?(outfile)
39
- i.write(outfile)
40
- assert_equal i.command, "gm convert -size 128x128 test/640.jpg +profile \\* " +
41
- "-quality 85 -gravity Center -crop 250x250 -resize 128x128 " +
42
- Shellwords.escape(outfile)
43
- assert File.exist?(outfile)
54
+ outfile
55
+ end
56
+
57
+ def test_bad_args
58
+ i = MicroMagick::Convert.new("test/640.jpg")
59
+ i.boing
60
+ assert_raise MicroMagick::InvalidArgument do
61
+ i.write(mktmpfile)
62
+ end
44
63
  end
45
64
  end
46
65
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_magick
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Matthew McEachen