mini_magick 1.2.5 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mini_magick might be problematic. Click here for more details.

@@ -1,6 +1,9 @@
1
1
  = MiniMagick
2
2
 
3
- A ruby wrapper for ImageMagick command line.
3
+ NOTE: I'm not actively using MiniMagick anymore and am looking to hand it off
4
+ to someone with more interest. Contact me through github if that person is you!
5
+
6
+ A ruby wrapper for ImageMagick or GraphicsMagick command line.
4
7
 
5
8
 
6
9
  == Why?
@@ -69,4 +72,4 @@ http://www.imagemagick.org/script/command-line-options.php#format
69
72
 
70
73
  == Requirements
71
74
 
72
- You must have ImageMagick installed.
75
+ You must have ImageMagick or GraphicsMagick installed.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/testtask'
3
3
  require 'rake/rdoctask'
4
+ require 'rake/gempackagetask'
4
5
 
5
6
  $:.unshift(File.dirname(__FILE__) + "/lib")
6
7
  require 'mini_magick'
@@ -10,7 +11,7 @@ task :default => :test
10
11
 
11
12
  desc 'Test the mini_magick plugin.'
12
13
  Rake::TestTask.new(:test) do |t|
13
- t.libs << 'lib'
14
+ t.libs << 'test'
14
15
  t.pattern = 'test/**/*_test.rb'
15
16
  t.verbose = true
16
17
  end
@@ -25,44 +26,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
25
26
  rdoc.rdoc_files.include('lib/**/*.rb')
26
27
  end
27
28
 
28
- # Jewler tasks
29
-
30
- begin
31
- require 'jeweler'
32
- Jeweler::Tasks.new do |gemspec|
33
- gemspec.name = "mini_magick"
34
- gemspec.summary = "Manipulate images with minimal use of memory."
35
- gemspec.email = "probablycorey@gmail.com"
36
- gemspec.homepage = "http://github.com/probablycorey/mini_magick"
37
- gemspec.authors = ["Corey Johnson"]
38
- gemspec.rubyforge_project = "mini-magick"
39
- end
40
- rescue LoadError
41
- puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
42
- end
43
-
44
- begin
45
- require 'rake/contrib/sshpublisher'
46
- namespace :rubyforge do
47
-
48
- desc "Release gem and RDoc documentation to RubyForge"
49
- task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
50
-
51
- namespace :release do
52
- desc "Publish RDoc to RubyForge."
53
- task :docs => [:rdoc] do
54
- config = YAML.load(
55
- File.read(File.expand_path('~/.rubyforge/user-config.yml'))
56
- )
57
-
58
- host = "#{config['username']}@rubyforge.org"
59
- remote_dir = "/var/www/gforge-projects/the-perfect-gem/"
60
- local_dir = 'rdoc'
61
-
62
- Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
63
- end
64
- end
65
- end
66
- rescue LoadError
67
- puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
29
+ spec = eval(File.read('mini_magick.gemspec'))
30
+ Rake::GemPackageTask.new(spec) do |pkg|
31
+ pkg.gem_spec = spec
68
32
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.5
1
+ 1.3.0
@@ -0,0 +1,2 @@
1
+ require 'mini_magick'
2
+ MiniMagick.processor = :gm
@@ -1,12 +1,14 @@
1
- require "open-uri"
2
- require "stringio"
3
- require "fileutils"
4
- require "open3"
5
-
6
- require File.join(File.dirname(__FILE__), '/image_temp_file')
1
+ require 'tempfile'
2
+ require 'subexec'
7
3
 
8
4
  module MiniMagick
9
- class MiniMagickError < RuntimeError; end
5
+ class << self
6
+ attr_accessor :processor
7
+ attr_accessor :timeout
8
+ end
9
+
10
+ class Error < RuntimeError; end
11
+ class Invalid < StandardError; end
10
12
 
11
13
  class Image
12
14
  attr :path
@@ -18,7 +20,7 @@ module MiniMagick
18
20
  class << self
19
21
  def from_blob(blob, ext = nil)
20
22
  begin
21
- tempfile = ImageTempFile.new(ext)
23
+ tempfile = Tempfile.new(['mini_magick', ext.to_s])
22
24
  tempfile.binmode
23
25
  tempfile.write(blob)
24
26
  ensure
@@ -84,14 +86,14 @@ module MiniMagick
84
86
  run_command("mogrify", "-format", format, @path)
85
87
 
86
88
  old_path = @path.dup
87
- @path.sub!(/(\.\w+)?$/, ".#{format}")
89
+ @path.sub!(/(\.\w*)?$/, ".#{format}")
88
90
  File.delete(old_path) unless old_path == @path
89
91
 
90
92
  unless File.exists?(@path)
91
93
  begin
92
94
  FileUtils.copy_file(@path.sub(".#{format}", "-#{page}.#{format}"), @path)
93
- rescue e
94
- raise MiniMagickError, "Unable to format to #{format}; #{e}" unless File.exist?(@path)
95
+ rescue => ex
96
+ raise MiniMagickError, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
95
97
  end
96
98
  end
97
99
  ensure
@@ -99,6 +101,12 @@ module MiniMagick
99
101
  File.unlink(fname)
100
102
  end
101
103
  end
104
+
105
+ # Collapse images with sequences to the first frame (ie. animated gifs) and
106
+ # preserve quality
107
+ def collapse!
108
+ run_command("mogrify", "-quality", "100", "#{path}[0]")
109
+ end
102
110
 
103
111
  # Writes the temporary image that we are using for processing to the output path
104
112
  def write(output_path)
@@ -143,22 +151,36 @@ module MiniMagick
143
151
  def run_command(command, *args)
144
152
  args.collect! do |arg|
145
153
  # args can contain characters like '>' so we must escape them, but don't quote switches
146
- if arg !~ /^\+|\-/
154
+ if arg !~ /^[\+\-]/
147
155
  "\"#{arg}\""
148
156
  else
149
157
  arg.to_s
150
158
  end
151
159
  end
152
160
 
153
- command = "#{command} #{args.join(' ')}"
154
- output = `#{command} 2>&1`
155
-
156
- if $?.exitstatus != 0
157
- raise MiniMagickError, "ImageMagick command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
161
+ command = "#{MiniMagick.processor} #{command} #{args.join(' ')}".strip
162
+ sub = Subexec.run(command, :timeout => MiniMagick.timeout)
163
+
164
+ if sub.exitstatus != 0
165
+ # Clean up after ourselves in case of an error
166
+ destroy!
167
+
168
+ # Raise the appropriate error
169
+ if sub.output =~ /no decode delegate/i || sub.output =~ /did not return an image/i
170
+ raise Invalid, sub.output
171
+ else
172
+ raise Error, "Command (#{command.inspect}) failed: #{{:status_code => sub.exitstatus, :output => sub.output}.inspect}"
173
+ end
158
174
  else
159
- output
175
+ sub.output
160
176
  end
161
177
  end
178
+
179
+ def destroy!
180
+ return if tempfile.nil?
181
+ File.unlink(tempfile.path)
182
+ @tempfile = nil
183
+ end
162
184
  end
163
185
 
164
186
  class CommandBuilder
@@ -1,12 +1,15 @@
1
1
  require 'test/unit'
2
2
  require File.join(File.dirname(__FILE__), '../lib/mini_magick')
3
3
 
4
+ MiniMagick.processor = :gm
5
+
4
6
  class ImageTest < Test::Unit::TestCase
5
7
  include MiniMagick
6
8
 
7
9
  CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
8
10
 
9
11
  SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
12
+ MINUS_IMAGE_PATH = CURRENT_DIR + "simple-minus.gif"
10
13
  TIFF_IMAGE_PATH = CURRENT_DIR + "leaves.tiff"
11
14
  NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
12
15
  GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
@@ -16,15 +19,18 @@ class ImageTest < Test::Unit::TestCase
16
19
  def test_image_from_blob
17
20
  File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
18
21
  image = Image.from_blob(f.read)
22
+ image.destroy!
19
23
  end
20
24
  end
21
25
 
22
26
  def test_image_from_file
23
27
  image = Image.from_file(SIMPLE_IMAGE_PATH)
28
+ image.destroy!
24
29
  end
25
30
 
26
31
  def test_image_new
27
32
  image = Image.new(SIMPLE_IMAGE_PATH)
33
+ image.destroy!
28
34
  end
29
35
 
30
36
  def test_image_write
@@ -37,11 +43,13 @@ class ImageTest < Test::Unit::TestCase
37
43
  ensure
38
44
  File.delete output_path
39
45
  end
46
+ image.destroy!
40
47
  end
41
48
 
42
49
  def test_not_an_image
43
- assert_raise(MiniMagickError) do
50
+ assert_raise(MiniMagick::Invalid) do
44
51
  image = Image.new(NOT_AN_IMAGE_PATH)
52
+ image.destroy!
45
53
  end
46
54
  end
47
55
 
@@ -51,6 +59,7 @@ class ImageTest < Test::Unit::TestCase
51
59
  assert_equal 55, image[:height]
52
60
  assert_equal [150, 55], image[:dimensions]
53
61
  assert_match(/^gif$/i, image[:format])
62
+ image.destroy!
54
63
  end
55
64
 
56
65
  def test_tiff
@@ -58,22 +67,26 @@ class ImageTest < Test::Unit::TestCase
58
67
  assert_equal "tiff", image[:format].downcase
59
68
  assert_equal 295, image[:width]
60
69
  assert_equal 242, image[:height]
70
+ image.destroy!
61
71
  end
62
72
 
63
- def test_animation_pages
64
- image = Image.from_file(ANIMATION_PATH)
65
- image.format "png", 0
66
- assert_equal "png", image[:format].downcase
67
- end
73
+ # def test_animation_pages
74
+ # image = Image.from_file(ANIMATION_PATH)
75
+ # image.format "png", 0
76
+ # assert_equal "png", image[:format].downcase
77
+ # image.destroy!
78
+ # end
68
79
 
69
- def test_animation_size
70
- image = Image.from_file(ANIMATION_PATH)
71
- assert_equal image[:size], 76631
72
- end
80
+ # def test_animation_size
81
+ # image = Image.from_file(ANIMATION_PATH)
82
+ # assert_equal image[:size], 76631
83
+ # image.destroy!
84
+ # end
73
85
 
74
86
  def test_gif_with_jpg_format
75
87
  image = Image.new(GIF_WITH_JPG_EXT)
76
88
  assert_equal "gif", image[:format].downcase
89
+ image.destroy!
77
90
  end
78
91
 
79
92
  def test_image_resize
@@ -83,6 +96,7 @@ class ImageTest < Test::Unit::TestCase
83
96
  assert_equal 20, image[:width]
84
97
  assert_equal 30, image[:height]
85
98
  assert_match(/^gif$/i, image[:format])
99
+ image.destroy!
86
100
  end
87
101
 
88
102
  def test_image_resize_with_minimum
@@ -92,6 +106,7 @@ class ImageTest < Test::Unit::TestCase
92
106
 
93
107
  assert_equal original_width, image[:width]
94
108
  assert_equal original_height, image[:height]
109
+ image.destroy!
95
110
  end
96
111
 
97
112
  def test_image_combine_options_resize_blur
@@ -104,6 +119,17 @@ class ImageTest < Test::Unit::TestCase
104
119
  assert_equal 20, image[:width]
105
120
  assert_equal 30, image[:height]
106
121
  assert_match(/^gif$/i, image[:format])
122
+ image.destroy!
123
+ end
124
+
125
+ def test_image_combine_options_with_filename_with_minusses_in_it
126
+ image = Image.from_file(SIMPLE_IMAGE_PATH)
127
+ assert_nothing_raised do
128
+ image.combine_options do |c|
129
+ c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
130
+ end
131
+ end
132
+ image.destroy!
107
133
  end
108
134
 
109
135
  def test_exif
@@ -111,6 +137,7 @@ class ImageTest < Test::Unit::TestCase
111
137
  assert_equal('0220', image["exif:ExifVersion"])
112
138
  image = Image.from_file(SIMPLE_IMAGE_PATH)
113
139
  assert_equal('', image["EXIF:ExifVersion"])
140
+ image.destroy!
114
141
  end
115
142
 
116
143
  def test_original_at
@@ -118,17 +145,20 @@ class ImageTest < Test::Unit::TestCase
118
145
  assert_equal(Time.local('2005', '2', '23', '23', '17', '24'), image[:original_at])
119
146
  image = Image.from_file(SIMPLE_IMAGE_PATH)
120
147
  assert_nil(image[:original_at])
148
+ image.destroy!
121
149
  end
122
150
 
123
151
  def test_tempfile_at_path
124
152
  image = Image.from_file(TIFF_IMAGE_PATH)
125
153
  assert_equal image.path, image.tempfile.path
154
+ image.destroy!
126
155
  end
127
156
 
128
157
  def test_tempfile_at_path_after_format
129
158
  image = Image.from_file(TIFF_IMAGE_PATH)
130
159
  image.format('png')
131
160
  assert_equal image.path, image.tempfile.path
161
+ image.destroy!
132
162
  end
133
163
 
134
164
  def test_previous_tempfile_deleted_after_format
@@ -136,12 +166,13 @@ class ImageTest < Test::Unit::TestCase
136
166
  before = image.path.dup
137
167
  image.format('png')
138
168
  assert !File.exist?(before)
169
+ image.destroy!
139
170
  end
140
171
 
141
- def test_mini_magick_error_when_referencing_not_existing_page
142
- image = Image.from_file(ANIMATION_PATH)
143
- assert_raises MiniMagickError do
144
- image.format('png', 31415)
145
- end
146
- end
172
+ # def test_mini_magick_error_when_referencing_not_existing_page
173
+ # image = Image.from_file(ANIMATION_PATH)
174
+ # image.format('png')
175
+ # assert_equal image[:format], 'PNG'
176
+ # image.destroy!
177
+ # end
147
178
  end
Binary file
metadata CHANGED
@@ -1,71 +1,107 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mini_magick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.5
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 3
9
+ - 0
10
+ version: 1.3.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Corey Johnson
14
+ - Peter Kieltyka
8
15
  autorequire:
9
16
  bindir: bin
10
17
  cert_chain: []
11
18
 
12
- date: 2009-05-27 00:00:00 +00:00
19
+ date: 2010-07-02 00:00:00 -07:00
13
20
  default_executable:
14
- dependencies: []
15
-
16
- description:
17
- email: probablycorey@gmail.com
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ name: subexec
24
+ prerelease: false
25
+ requirement: &id001 !ruby/object:Gem::Requirement
26
+ none: false
27
+ requirements:
28
+ - - ~>
29
+ - !ruby/object:Gem::Version
30
+ hash: 27
31
+ segments:
32
+ - 0
33
+ - 0
34
+ - 2
35
+ version: 0.0.2
36
+ type: :runtime
37
+ version_requirements: *id001
38
+ description: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
39
+ email:
40
+ - probablycorey@gmail.com
41
+ - peter@nulayer.com
18
42
  executables: []
19
43
 
20
44
  extensions: []
21
45
 
22
- extra_rdoc_files:
23
- - README.rdoc
46
+ extra_rdoc_files: []
47
+
24
48
  files:
25
- - .gitignore
26
- - MIT-LICENSE
27
49
  - README.rdoc
28
- - Rakefile
29
50
  - VERSION
30
- - lib/image_temp_file.rb
51
+ - MIT-LICENSE
52
+ - Rakefile
53
+ - lib/mini_gmagick.rb
31
54
  - lib/mini_magick.rb
32
- - mini_magick.gemspec
33
55
  - test/actually_a_gif.jpg
34
56
  - test/animation.gif
35
57
  - test/command_builder_test.rb
36
- - test/image_temp_file_test.rb
37
58
  - test/image_test.rb
38
59
  - test/leaves.tiff
39
60
  - test/not_an_image.php
61
+ - test/simple-minus.gif
40
62
  - test/simple.gif
41
63
  - test/trogdor.jpg
42
64
  has_rdoc: true
43
- homepage: http://github.com/probablycorey/mini_magick
65
+ homepage: http://github.com/nulayer/mini_magick
66
+ licenses: []
67
+
44
68
  post_install_message:
45
- rdoc_options:
46
- - --charset=UTF-8
69
+ rdoc_options: []
70
+
47
71
  require_paths:
48
72
  - lib
49
73
  required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
50
75
  requirements:
51
76
  - - ">="
52
77
  - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
53
81
  version: "0"
54
- version:
55
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
56
84
  requirements:
57
85
  - - ">="
58
86
  - !ruby/object:Gem::Version
87
+ hash: 3
88
+ segments:
89
+ - 0
59
90
  version: "0"
60
- version:
61
91
  requirements: []
62
92
 
63
- rubyforge_project: mini-magick
64
- rubygems_version: 1.3.1
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
65
95
  signing_key:
66
- specification_version: 2
67
- summary: Manipulate images with minimal use of memory.
96
+ specification_version: 3
97
+ summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
68
98
  test_files:
99
+ - test/actually_a_gif.jpg
100
+ - test/animation.gif
69
101
  - test/command_builder_test.rb
70
- - test/image_temp_file_test.rb
71
102
  - test/image_test.rb
103
+ - test/leaves.tiff
104
+ - test/not_an_image.php
105
+ - test/simple-minus.gif
106
+ - test/simple.gif
107
+ - test/trogdor.jpg
data/.gitignore DELETED
@@ -1 +0,0 @@
1
- /pkg
@@ -1,9 +0,0 @@
1
- require "tempfile"
2
-
3
- module MiniMagick
4
- class ImageTempFile < Tempfile
5
- def make_tmpname(ext, n)
6
- 'mini_magick%d-%d%s' % [$$, n, ext ? ".#{ext}" : '']
7
- end
8
- end
9
- end
@@ -1,55 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- Gem::Specification.new do |s|
4
- s.name = %q{mini_magick}
5
- s.version = "1.2.5"
6
-
7
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
- s.authors = ["Corey Johnson"]
9
- s.date = %q{2009-05-27}
10
- s.email = %q{probablycorey@gmail.com}
11
- s.extra_rdoc_files = [
12
- "README.rdoc"
13
- ]
14
- s.files = [
15
- ".gitignore",
16
- "MIT-LICENSE",
17
- "README.rdoc",
18
- "Rakefile",
19
- "VERSION",
20
- "lib/image_temp_file.rb",
21
- "lib/mini_magick.rb",
22
- "mini_magick.gemspec",
23
- "test/actually_a_gif.jpg",
24
- "test/animation.gif",
25
- "test/command_builder_test.rb",
26
- "test/image_temp_file_test.rb",
27
- "test/image_test.rb",
28
- "test/leaves.tiff",
29
- "test/not_an_image.php",
30
- "test/simple.gif",
31
- "test/trogdor.jpg"
32
- ]
33
- s.has_rdoc = true
34
- s.homepage = %q{http://github.com/probablycorey/mini_magick}
35
- s.rdoc_options = ["--charset=UTF-8"]
36
- s.require_paths = ["lib"]
37
- s.rubyforge_project = %q{mini-magick}
38
- s.rubygems_version = %q{1.3.1}
39
- s.summary = %q{Manipulate images with minimal use of memory.}
40
- s.test_files = [
41
- "test/command_builder_test.rb",
42
- "test/image_temp_file_test.rb",
43
- "test/image_test.rb"
44
- ]
45
-
46
- if s.respond_to? :specification_version then
47
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
48
- s.specification_version = 2
49
-
50
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
51
- else
52
- end
53
- else
54
- end
55
- end
@@ -1,17 +0,0 @@
1
- require 'test/unit'
2
- require File.join(File.dirname(__FILE__), '../lib/image_temp_file')
3
-
4
- class ImageTempFileTest < Test::Unit::TestCase
5
- include MiniMagick
6
-
7
- def test_multiple_calls_yield_different_files
8
- first = ImageTempFile.new('test')
9
- second = ImageTempFile.new('test')
10
- assert_not_equal first.path, second.path
11
- end
12
-
13
- def test_temp_file_has_given_extension
14
- assert_match /^[^.]+\.jpg$/, ImageTempFile.new('jpg').path
15
- assert_match /^[^.]+\.png$/, ImageTempFile.new('png').path
16
- end
17
- end