mini_magick 2.3 → 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.
- data/VERSION +1 -1
- data/lib/mini_magick.rb +38 -15
- data/test/image_test.rb +25 -3
- metadata +18 -17
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0
|
data/lib/mini_magick.rb
CHANGED
@@ -1,11 +1,23 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require 'subexec'
|
3
|
-
require 'open-uri'
|
4
3
|
|
5
4
|
module MiniMagick
|
6
5
|
class << self
|
7
6
|
attr_accessor :processor
|
8
7
|
attr_accessor :timeout
|
8
|
+
|
9
|
+
|
10
|
+
# Experimental method for automatically selecting a processor
|
11
|
+
# such as gm. Only works on *nix.
|
12
|
+
#
|
13
|
+
# TODO: Write tests for this and figure out what platforms it supports
|
14
|
+
def choose_processor
|
15
|
+
if `type -P mogrify`.size > 0
|
16
|
+
return
|
17
|
+
elsif `type -P gm`.size > 0
|
18
|
+
self.processor = "gm"
|
19
|
+
end
|
20
|
+
end
|
9
21
|
end
|
10
22
|
|
11
23
|
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append authenticate auto-gamma auto-level auto-orient background bench iterations bias black-threshold blue-primary point blue-shift factor blur border bordercolor brightness-contrast caption string cdl filename channel type charcoal radius chop clip clamp clip-mask filename clip-path id clone index clut contrast-stretch coalesce colorize color-matrix colors colorspace type combine comment string compose operator composite compress type contrast convolve coefficients crop cycle amount decipher filename debug events define format:option deconstruct delay delete index density depth despeckle direction type display server dispose method distort type coefficients dither method draw string edge radius emboss radius encipher filename encoding type endian type enhance equalize evaluate operator evaluate-sequence operator extent extract family name fft fill filter type flatten flip floodfill flop font name format string frame function name fuzz distance fx expression gamma gaussian-blur geometry gravity type green-primary point help identify ifft implode amount insert index intent type interlace type interline-spacing interpolate method interword-spacing kerning label string lat layers method level limit type linear-stretch liquid-rescale log format loop iterations mask filename mattecolor median radius modulate monitor monochrome morph morphology method kernel motion-blur negate noise radius normalize opaque ordered-dither NxN orient type page paint radius ping pointsize polaroid angle posterize levels precision preview type print string process image-filter profile filename quality quantizespace quiet radial-blur angle raise random-threshold low,high red-primary point regard-warnings region remap filename render repage resample resize respect-parentheses roll rotate degrees sample sampling-factor scale scene seed segments selective-blur separate sepia-tone threshold set attribute shade degrees shadow sharpen shave shear sigmoidal-contrast size sketch solarize threshold splice spread radius strip stroke strokewidth stretch type style type swap indexes swirl degrees texture filename threshold thumbnail tile filename tile-offset tint transform transparent transparent-color transpose transverse treedepth trim type type undercolor unique-colors units type unsharp verbose version view vignette virtual-pixel method wave weight type white-point point white-threshold write filename}
|
@@ -55,9 +67,7 @@ module MiniMagick
|
|
55
67
|
#
|
56
68
|
# Extension is either guessed from the path or you can specify it as a second parameter.
|
57
69
|
#
|
58
|
-
# If you pass in what looks like a URL, we
|
59
|
-
# then we require 'open-uri'. That way, if you have a work-alike library, we won't demolish it.
|
60
|
-
# Open-uri never gets required unless you pass in something with "://" in it.
|
70
|
+
# If you pass in what looks like a URL, we require 'open-uri' before opening it.
|
61
71
|
#
|
62
72
|
# @param file_or_url [String] Either a local file path or a URL that open-uri can read
|
63
73
|
# @param ext [String] Specify the extension you want to read it as
|
@@ -65,9 +75,7 @@ module MiniMagick
|
|
65
75
|
def open(file_or_url, ext = File.extname(file_or_url))
|
66
76
|
file_or_url = file_or_url.to_s # Force it to be a String... hell or highwater
|
67
77
|
if file_or_url.include?("://")
|
68
|
-
|
69
|
-
require 'open-uri'
|
70
|
-
end
|
78
|
+
require 'open-uri'
|
71
79
|
self.read(Kernel::open(file_or_url), ext)
|
72
80
|
else
|
73
81
|
File.open(file_or_url, "rb") do |f|
|
@@ -111,7 +119,7 @@ module MiniMagick
|
|
111
119
|
|
112
120
|
# Create a new MiniMagick::Image object
|
113
121
|
#
|
114
|
-
# _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
|
122
|
+
# _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
|
115
123
|
# you can either copy it yourself or use the MiniMagick::Image.open(path) method which creates a
|
116
124
|
# temporary file for you and protects your original!
|
117
125
|
#
|
@@ -214,7 +222,7 @@ module MiniMagick
|
|
214
222
|
begin
|
215
223
|
FileUtils.copy_file(@path.sub(".#{format}", "-#{page}.#{format}"), @path)
|
216
224
|
rescue => ex
|
217
|
-
raise
|
225
|
+
raise MiniMagick::Error, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
|
218
226
|
end
|
219
227
|
end
|
220
228
|
ensure
|
@@ -229,10 +237,25 @@ module MiniMagick
|
|
229
237
|
run_command("mogrify", "-quality", "100", "#{path}[0]")
|
230
238
|
end
|
231
239
|
|
240
|
+
# Writes the temporary file out to either a file location (by passing in a String) or by
|
241
|
+
# passing in a Stream that you can #write(chunk) to repeatedly
|
242
|
+
#
|
243
|
+
# @param output_to [IOStream, String] Some kind of stream object that needs to be read or a file path as a String
|
244
|
+
# @return [IOStream, Boolean] If you pass in a file location [String] then you get a success boolean. If its a stream, you get it back.
|
232
245
|
# Writes the temporary image that we are using for processing to the output path
|
233
|
-
def write(
|
234
|
-
|
235
|
-
|
246
|
+
def write(output_to)
|
247
|
+
if output_to.kind_of?(String) || !output_to.respond_to?(:write)
|
248
|
+
FileUtils.copy_file @path, output_to
|
249
|
+
run_command "identify", output_to # Verify that we have a good image
|
250
|
+
else # stream
|
251
|
+
File.open(@path, "rb") do |f|
|
252
|
+
f.binmode
|
253
|
+
while chunk = f.read(8192)
|
254
|
+
output_to.write(chunk)
|
255
|
+
end
|
256
|
+
end
|
257
|
+
output_to
|
258
|
+
end
|
236
259
|
end
|
237
260
|
|
238
261
|
# Gives you raw image data back
|
@@ -255,14 +278,14 @@ module MiniMagick
|
|
255
278
|
|
256
279
|
# You can use multiple commands together using this method. Very easy to use!
|
257
280
|
#
|
258
|
-
# @example
|
281
|
+
# @example
|
259
282
|
# image.combine_options do |c|
|
260
283
|
# c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
|
261
284
|
# c.thumbnail "300x500>"
|
262
285
|
# c.background background
|
263
286
|
# end
|
264
287
|
#
|
265
|
-
# @yieldparam command [CommandBuilder]
|
288
|
+
# @yieldparam command [CommandBuilder]
|
266
289
|
def combine_options(&block)
|
267
290
|
c = CommandBuilder.new('mogrify')
|
268
291
|
block.call(c)
|
@@ -272,7 +295,7 @@ module MiniMagick
|
|
272
295
|
|
273
296
|
# Check to see if we are running on win32 -- we need to escape things differently
|
274
297
|
def windows?
|
275
|
-
!(RUBY_PLATFORM =~ /win32/).nil?
|
298
|
+
!(RUBY_PLATFORM =~ /win32|mswin|mingw/).nil?
|
276
299
|
end
|
277
300
|
|
278
301
|
def composite(other_image, output_extension = 'jpg', &block)
|
data/test/image_test.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
-
require '
|
3
|
+
require 'mocha'
|
4
4
|
require 'pathname'
|
5
|
+
require 'stringio'
|
5
6
|
require File.expand_path('../../lib/mini_magick', __FILE__)
|
6
7
|
|
7
8
|
#MiniMagick.processor = :gm
|
@@ -50,7 +51,7 @@ class ImageTest < Test::Unit::TestCase
|
|
50
51
|
image = Image.new(SIMPLE_IMAGE_PATH)
|
51
52
|
image.destroy!
|
52
53
|
end
|
53
|
-
|
54
|
+
|
54
55
|
def test_remote_image
|
55
56
|
image = Image.open("http://www.google.com/images/logos/logo.png")
|
56
57
|
image.valid?
|
@@ -70,6 +71,15 @@ class ImageTest < Test::Unit::TestCase
|
|
70
71
|
image.destroy!
|
71
72
|
end
|
72
73
|
|
74
|
+
def test_image_write_with_stream
|
75
|
+
stream = StringIO.new
|
76
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
77
|
+
image.write("/tmp/foo.gif")
|
78
|
+
image.write(stream)
|
79
|
+
# assert Image.read(stream.string).valid?
|
80
|
+
image.destroy!
|
81
|
+
end
|
82
|
+
|
73
83
|
def test_not_an_image
|
74
84
|
image = Image.new(NOT_AN_IMAGE_PATH)
|
75
85
|
assert_equal false, image.valid?
|
@@ -220,7 +230,7 @@ class ImageTest < Test::Unit::TestCase
|
|
220
230
|
end
|
221
231
|
image.destroy!
|
222
232
|
end
|
223
|
-
|
233
|
+
|
224
234
|
# http://github.com/probablycorey/mini_magick/issues#issue/15
|
225
235
|
def test_issue_15
|
226
236
|
image = Image.open(Pathname.new(SIMPLE_IMAGE_PATH))
|
@@ -239,4 +249,16 @@ class ImageTest < Test::Unit::TestCase
|
|
239
249
|
end
|
240
250
|
image.destroy!
|
241
251
|
end
|
252
|
+
|
253
|
+
# testing that if copying files formatted from an animation fails,
|
254
|
+
# it raises an appropriate error
|
255
|
+
def test_throw_animation_copy_after_format_error
|
256
|
+
image = Image.open(ANIMATION_PATH)
|
257
|
+
FileUtils.stubs(:copy_file).raises(Errno::ENOENT)
|
258
|
+
assert_raises MiniMagick::Error do
|
259
|
+
image.format('png')
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
|
242
264
|
end
|
metadata
CHANGED
@@ -3,9 +3,9 @@ name: mini_magick
|
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
|
-
- 2
|
7
6
|
- 3
|
8
|
-
|
7
|
+
- 0
|
8
|
+
version: "3.0"
|
9
9
|
platform: ruby
|
10
10
|
authors:
|
11
11
|
- Corey Johnson
|
@@ -15,14 +15,13 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-10-
|
18
|
+
date: 2010-10-28 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: subexec
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
25
|
requirements:
|
27
26
|
- - ~>
|
28
27
|
- !ruby/object:Gem::Version
|
@@ -33,6 +32,20 @@ dependencies:
|
|
33
32
|
version: 0.0.4
|
34
33
|
type: :runtime
|
35
34
|
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: mocha
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
- 9
|
45
|
+
- 9
|
46
|
+
version: 0.9.9
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
36
49
|
description: ""
|
37
50
|
email:
|
38
51
|
- probablycorey@gmail.com
|
@@ -51,16 +64,6 @@ files:
|
|
51
64
|
- Rakefile
|
52
65
|
- lib/mini_gmagick.rb
|
53
66
|
- lib/mini_magick.rb
|
54
|
-
- test/actually_a_gif.jpg
|
55
|
-
- test/animation.gif
|
56
|
-
- test/command_builder_test.rb
|
57
|
-
- test/composited.jpg
|
58
|
-
- test/image_test.rb
|
59
|
-
- test/leaves.tiff
|
60
|
-
- test/not_an_image.php
|
61
|
-
- test/simple-minus.gif
|
62
|
-
- test/simple.gif
|
63
|
-
- test/trogdor.jpg
|
64
67
|
has_rdoc: true
|
65
68
|
homepage: http://github.com/probablycorey/mini_magick
|
66
69
|
licenses: []
|
@@ -71,7 +74,6 @@ rdoc_options: []
|
|
71
74
|
require_paths:
|
72
75
|
- lib
|
73
76
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
77
|
requirements:
|
76
78
|
- - ">="
|
77
79
|
- !ruby/object:Gem::Version
|
@@ -79,7 +81,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
81
|
- 0
|
80
82
|
version: "0"
|
81
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
84
|
requirements:
|
84
85
|
- - ">="
|
85
86
|
- !ruby/object:Gem::Version
|
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
requirements: []
|
90
91
|
|
91
92
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.3.
|
93
|
+
rubygems_version: 1.3.6
|
93
94
|
signing_key:
|
94
95
|
specification_version: 3
|
95
96
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|