mini_magick 2.1 → 2.3
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/README.rdoc +19 -8
- data/VERSION +1 -1
- data/lib/mini_magick.rb +167 -50
- data/test/image_test.rb +63 -30
- data/test/leaves.tiff +0 -0
- metadata +3 -7
data/README.rdoc
CHANGED
@@ -32,24 +32,35 @@ has (Found here http://www.imagemagick.org/script/mogrify.php)
|
|
32
32
|
|
33
33
|
Want to make a thumbnail from a file...
|
34
34
|
|
35
|
-
image = MiniMagick::Image.
|
35
|
+
image = MiniMagick::Image.open("input.jpg")
|
36
36
|
image.resize "100x100"
|
37
|
-
image.write
|
37
|
+
image.write "output.jpg"
|
38
38
|
|
39
39
|
Want to make a thumbnail from a blob...
|
40
40
|
|
41
|
-
image = MiniMagick::Image.
|
41
|
+
image = MiniMagick::Image.read(blob)
|
42
42
|
image.resize "100x100"
|
43
|
-
image.write
|
43
|
+
image.write "output.jpg"
|
44
|
+
|
45
|
+
Got an incoming IOStream?
|
46
|
+
|
47
|
+
image = MiniMagick::Image.read(stream)
|
48
|
+
|
49
|
+
Want to make a thumbnail of a remote image?
|
50
|
+
|
51
|
+
image = MiniMagick::Image.open("http://www.google.com/images/logos/logo.png")
|
52
|
+
image.resize "5x5"
|
53
|
+
image.format "gif"
|
54
|
+
image.write "localcopy.gif"
|
44
55
|
|
45
56
|
Need to combine several options?
|
46
57
|
|
47
|
-
image = MiniMagick::Image.
|
58
|
+
image = MiniMagick::Image.open("input.jpg")
|
48
59
|
image.combine_options do |c|
|
49
60
|
c.sample "50%"
|
50
61
|
c.rotate "-90>"
|
51
62
|
end
|
52
|
-
image.write
|
63
|
+
image.write "output.jpg"
|
53
64
|
|
54
65
|
Want to composite two images? Super easy! (Aka, put a watermark on!)
|
55
66
|
|
@@ -57,7 +68,7 @@ Want to composite two images? Super easy! (Aka, put a watermark on!)
|
|
57
68
|
result = image.composite(Image.open("watermark.png", "jpg") do |c|
|
58
69
|
c.gravity "center"
|
59
70
|
end
|
60
|
-
result.write
|
71
|
+
result.write "my_output_file.jpg"
|
61
72
|
|
62
73
|
Want to manipulate an image at its source (You won't have to write it
|
63
74
|
out because the transformations are done on that file)
|
@@ -67,7 +78,7 @@ out because the transformations are done on that file)
|
|
67
78
|
|
68
79
|
Want to get some meta-information out?
|
69
80
|
|
70
|
-
image = MiniMagick::Image.
|
81
|
+
image = MiniMagick::Image.open("input.jpg")
|
71
82
|
image[:width] # will get the width (you can also use :height and :format)
|
72
83
|
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
|
73
84
|
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.3
|
data/lib/mini_magick.rb
CHANGED
@@ -1,57 +1,135 @@
|
|
1
1
|
require 'tempfile'
|
2
2
|
require 'subexec'
|
3
|
+
require 'open-uri'
|
3
4
|
|
4
5
|
module MiniMagick
|
5
6
|
class << self
|
6
7
|
attr_accessor :processor
|
7
8
|
attr_accessor :timeout
|
8
9
|
end
|
9
|
-
|
10
|
+
|
10
11
|
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}
|
11
12
|
|
12
13
|
class Error < RuntimeError; end
|
13
14
|
class Invalid < StandardError; end
|
14
15
|
|
15
16
|
class Image
|
17
|
+
# @return [String] The location of the current working file
|
16
18
|
attr :path
|
17
|
-
attr :tempfile
|
18
|
-
attr :output
|
19
19
|
|
20
20
|
# Class Methods
|
21
21
|
# -------------
|
22
22
|
class << self
|
23
|
+
# This is the primary loading method used by all of the other class methods.
|
24
|
+
#
|
25
|
+
# Use this to pass in a stream object. Must respond to Object#read(size) or be a binary string object (BLOBBBB)
|
26
|
+
#
|
27
|
+
# As a change from the old API, please try and use IOStream objects. They are much, much better and more efficient!
|
28
|
+
#
|
29
|
+
# Probably easier to use the #open method if you want to open a file or a URL.
|
30
|
+
#
|
31
|
+
# @param stream [IOStream, String] Some kind of stream object that needs to be read or is a binary String blob!
|
32
|
+
# @param ext [String] A manual extension to use for reading the file. Not required, but if you are having issues, give this a try.
|
33
|
+
# @return [Image]
|
34
|
+
def read(stream, ext = nil)
|
35
|
+
if stream.is_a?(String)
|
36
|
+
stream = StringIO.new(stream)
|
37
|
+
end
|
38
|
+
|
39
|
+
create(ext) do |f|
|
40
|
+
while chunk = stream.read(8192)
|
41
|
+
f.write(chunk)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# @deprecated Please use Image.read instead!
|
23
47
|
def from_blob(blob, ext = nil)
|
48
|
+
warn "Warning: MiniMagick::Image.from_blob method is deprecated. Instead, please use Image.read"
|
49
|
+
create(ext) { |f| f.write(blob) }
|
50
|
+
end
|
51
|
+
|
52
|
+
# Opens a specific image file either on the local file system or at a URI.
|
53
|
+
#
|
54
|
+
# Use this if you don't want to overwrite the image file.
|
55
|
+
#
|
56
|
+
# Extension is either guessed from the path or you can specify it as a second parameter.
|
57
|
+
#
|
58
|
+
# If you pass in what looks like a URL, we will see if Kernel#open exists. If it doesn't
|
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.
|
61
|
+
#
|
62
|
+
# @param file_or_url [String] Either a local file path or a URL that open-uri can read
|
63
|
+
# @param ext [String] Specify the extension you want to read it as
|
64
|
+
# @return [Image] The loaded image
|
65
|
+
def open(file_or_url, ext = File.extname(file_or_url))
|
66
|
+
file_or_url = file_or_url.to_s # Force it to be a String... hell or highwater
|
67
|
+
if file_or_url.include?("://")
|
68
|
+
if !Kernel.respond_to?("open")
|
69
|
+
require 'open-uri'
|
70
|
+
end
|
71
|
+
self.read(Kernel::open(file_or_url), ext)
|
72
|
+
else
|
73
|
+
File.open(file_or_url, "rb") do |f|
|
74
|
+
self.read(f, ext)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# @deprecated Please use MiniMagick::Image.open(file_or_url) now
|
80
|
+
def from_file(file, ext = nil)
|
81
|
+
warn "Warning: MiniMagick::Image.from_file is now deprecated. Please use Image.open"
|
82
|
+
open(file, ext)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Used to create a new Image object data-copy. Not used to "paint" or that kind of thing.
|
86
|
+
#
|
87
|
+
# Takes an extension in a block and can be used to build a new Image object. Used
|
88
|
+
# by both #open and #read to create a new object! Ensures we have a good tempfile!
|
89
|
+
#
|
90
|
+
# @param ext [String] Specify the extension you want to read it as
|
91
|
+
# @yield [IOStream] You can #write bits to this object to create the new Image
|
92
|
+
# @return [Image] The created image
|
93
|
+
def create(ext = nil, &block)
|
24
94
|
begin
|
25
95
|
tempfile = Tempfile.new(['mini_magick', ext.to_s])
|
26
96
|
tempfile.binmode
|
27
|
-
|
28
|
-
|
29
|
-
tempfile.close if tempfile
|
30
|
-
end
|
97
|
+
block.call(tempfile)
|
98
|
+
tempfile.close
|
31
99
|
|
32
|
-
|
33
|
-
if !image.valid?
|
34
|
-
raise MiniMagick::Invalid
|
35
|
-
end
|
36
|
-
image
|
37
|
-
end
|
100
|
+
image = self.new(tempfile.path, tempfile)
|
38
101
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
102
|
+
if !image.valid?
|
103
|
+
raise MiniMagick::Invalid
|
104
|
+
end
|
105
|
+
return image
|
106
|
+
ensure
|
107
|
+
tempfile.close if tempfile
|
43
108
|
end
|
44
109
|
end
|
45
|
-
alias_method :from_file, :open
|
46
110
|
end
|
47
111
|
|
48
|
-
#
|
49
|
-
#
|
50
|
-
|
112
|
+
# Create a new MiniMagick::Image object
|
113
|
+
#
|
114
|
+
# _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
|
115
|
+
# you can either copy it yourself or use the MiniMagick::Image.open(path) method which creates a
|
116
|
+
# temporary file for you and protects your original!
|
117
|
+
#
|
118
|
+
# @param input_path [String] The location of an image file
|
119
|
+
# @todo Allow this to accept a block that can pass off to Image#combine_options
|
120
|
+
def initialize(input_path, tempfile = nil)
|
51
121
|
@path = input_path
|
52
122
|
@tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
|
53
123
|
end
|
54
|
-
|
124
|
+
|
125
|
+
|
126
|
+
# Checks to make sure that MiniMagick can read the file and understand it.
|
127
|
+
#
|
128
|
+
# This uses the 'identify' command line utility to check the file. If you are having
|
129
|
+
# issues with this, then please work directly with the 'identify' command and see if you
|
130
|
+
# can figure out what the issue is.
|
131
|
+
#
|
132
|
+
# @return [Boolean]
|
55
133
|
def valid?
|
56
134
|
run_command("identify", @path)
|
57
135
|
true
|
@@ -59,7 +137,21 @@ module MiniMagick
|
|
59
137
|
false
|
60
138
|
end
|
61
139
|
|
62
|
-
#
|
140
|
+
# A rather low-level way to interact with the "identify" command. No nice API here, just
|
141
|
+
# the crazy stuff you find in ImageMagick. See the examples listed!
|
142
|
+
#
|
143
|
+
# @example
|
144
|
+
# image["format"] #=> "TIFF"
|
145
|
+
# image["height"] #=> 41 (pixels)
|
146
|
+
# image["width"] #=> 50 (pixels)
|
147
|
+
# image["dimensions"] #=> [50, 41]
|
148
|
+
# image["size"] #=> 2050 (bits)
|
149
|
+
# image["original_at"] #=> 2005-02-23 23:17:24 +0000 (Read from Exif data)
|
150
|
+
# image["EXIF:ExifVersion"] #=> "0220" (Can read anything from Exif)
|
151
|
+
#
|
152
|
+
# @param format [String] A format for the "identify" command
|
153
|
+
# @see For reference see http://www.imagemagick.org/script/command-line-options.php#format
|
154
|
+
# @return [String, Numeric, Array, Time, Object] Depends on the method called! Defaults to String for unknown commands
|
63
155
|
def [](value)
|
64
156
|
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
|
65
157
|
case value.to_s
|
@@ -88,21 +180,35 @@ module MiniMagick
|
|
88
180
|
end
|
89
181
|
end
|
90
182
|
|
91
|
-
# Sends raw commands to imagemagick's mogrify command. The image path is automatically appended to the command
|
183
|
+
# Sends raw commands to imagemagick's `mogrify` command. The image path is automatically appended to the command.
|
184
|
+
#
|
185
|
+
# Remember, we are always acting on this instance of the Image when messing with this.
|
186
|
+
#
|
187
|
+
# @return [String] Whatever the result from the command line is. May not be terribly useful.
|
92
188
|
def <<(*args)
|
93
189
|
run_command("mogrify", *args << @path)
|
94
190
|
end
|
95
191
|
|
96
|
-
# This is
|
192
|
+
# This is used to change the format of the image. That is, from "tiff to jpg" or something like that.
|
193
|
+
# Once you run it, the instance is pointing to a new file with a new extension!
|
194
|
+
#
|
195
|
+
# *DANGER*: This renames the file that the instance is pointing to. So, if you manually opened the
|
196
|
+
# file with Image.new(file_path)... then that file is DELETED! If you used Image.open(file) then
|
197
|
+
# you are ok. The original file will still be there. But, any changes to it might not be...
|
198
|
+
#
|
97
199
|
# Formatting an animation into a non-animated type will result in ImageMagick creating multiple
|
98
200
|
# pages (starting with 0). You can choose which page you want to manipulate. We default to the
|
99
201
|
# first page.
|
100
|
-
|
202
|
+
#
|
203
|
+
# @param format [String] The target format... like 'jpg', 'gif', 'tiff', etc.
|
204
|
+
# @param page [Integer] If this is an animated gif, say which 'page' you want with an integer. Leave as default if you don't care.
|
205
|
+
# @return [nil]
|
206
|
+
def format(format, page = 0)
|
101
207
|
run_command("mogrify", "-format", format, @path)
|
102
208
|
|
103
209
|
old_path = @path.dup
|
104
210
|
@path.sub!(/(\.\w*)?$/, ".#{format}")
|
105
|
-
File.delete(old_path)
|
211
|
+
File.delete(old_path) if old_path != @path
|
106
212
|
|
107
213
|
unless File.exists?(@path)
|
108
214
|
begin
|
@@ -116,7 +222,7 @@ module MiniMagick
|
|
116
222
|
File.unlink(fname)
|
117
223
|
end
|
118
224
|
end
|
119
|
-
|
225
|
+
|
120
226
|
# Collapse images with sequences to the first frame (ie. animated gifs) and
|
121
227
|
# preserve quality
|
122
228
|
def collapse!
|
@@ -129,7 +235,8 @@ module MiniMagick
|
|
129
235
|
run_command "identify", output_path # Verify that we have a good image
|
130
236
|
end
|
131
237
|
|
132
|
-
#
|
238
|
+
# Gives you raw image data back
|
239
|
+
# @return [String] binary string
|
133
240
|
def to_blob
|
134
241
|
f = File.new @path
|
135
242
|
f.binmode
|
@@ -146,7 +253,16 @@ module MiniMagick
|
|
146
253
|
end
|
147
254
|
end
|
148
255
|
|
149
|
-
# You can use multiple commands together using this method
|
256
|
+
# You can use multiple commands together using this method. Very easy to use!
|
257
|
+
#
|
258
|
+
# @example
|
259
|
+
# image.combine_options do |c|
|
260
|
+
# c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
|
261
|
+
# c.thumbnail "300x500>"
|
262
|
+
# c.background background
|
263
|
+
# end
|
264
|
+
#
|
265
|
+
# @yieldparam command [CommandBuilder]
|
150
266
|
def combine_options(&block)
|
151
267
|
c = CommandBuilder.new('mogrify')
|
152
268
|
block.call(c)
|
@@ -158,23 +274,23 @@ module MiniMagick
|
|
158
274
|
def windows?
|
159
275
|
!(RUBY_PLATFORM =~ /win32/).nil?
|
160
276
|
end
|
161
|
-
|
277
|
+
|
162
278
|
def composite(other_image, output_extension = 'jpg', &block)
|
163
279
|
begin
|
164
|
-
|
165
|
-
|
280
|
+
second_tempfile = Tempfile.new(output_extension)
|
281
|
+
second_tempfile.binmode
|
166
282
|
ensure
|
167
|
-
|
283
|
+
second_tempfile.close
|
168
284
|
end
|
169
|
-
|
285
|
+
|
170
286
|
command = CommandBuilder.new("composite")
|
171
287
|
block.call(command) if block
|
172
288
|
command.push(other_image.path)
|
173
289
|
command.push(self.path)
|
174
|
-
command.push(
|
175
|
-
|
290
|
+
command.push(second_tempfile.path)
|
291
|
+
|
176
292
|
run(command)
|
177
|
-
return Image.new(
|
293
|
+
return Image.new(second_tempfile.path, second_tempfile)
|
178
294
|
end
|
179
295
|
|
180
296
|
# Outputs a carriage-return delimited format string for Unix and Windows
|
@@ -185,7 +301,7 @@ module MiniMagick
|
|
185
301
|
def run_command(command, *args)
|
186
302
|
run(CommandBuilder.new(command, *args))
|
187
303
|
end
|
188
|
-
|
304
|
+
|
189
305
|
def run(command_builder)
|
190
306
|
command = command_builder.command
|
191
307
|
|
@@ -194,7 +310,7 @@ module MiniMagick
|
|
194
310
|
if sub.exitstatus != 0
|
195
311
|
# Clean up after ourselves in case of an error
|
196
312
|
destroy!
|
197
|
-
|
313
|
+
|
198
314
|
# Raise the appropriate error
|
199
315
|
if sub.output =~ /no decode delegate/i || sub.output =~ /did not return an image/i
|
200
316
|
raise Invalid, sub.output
|
@@ -207,13 +323,13 @@ module MiniMagick
|
|
207
323
|
sub.output
|
208
324
|
end
|
209
325
|
end
|
210
|
-
|
326
|
+
|
211
327
|
def destroy!
|
212
|
-
return if tempfile.nil?
|
213
|
-
File.unlink(tempfile.path)
|
328
|
+
return if @tempfile.nil?
|
329
|
+
File.unlink(@tempfile.path)
|
214
330
|
@tempfile = nil
|
215
331
|
end
|
216
|
-
|
332
|
+
|
217
333
|
private
|
218
334
|
# Sometimes we get back a list of character values
|
219
335
|
def read_character_data(list_of_characters)
|
@@ -235,11 +351,11 @@ module MiniMagick
|
|
235
351
|
@args = []
|
236
352
|
options.each { |arg| push(arg) }
|
237
353
|
end
|
238
|
-
|
354
|
+
|
239
355
|
def command
|
240
356
|
"#{MiniMagick.processor} #{@command} #{@args.join(' ')}".strip
|
241
357
|
end
|
242
|
-
|
358
|
+
|
243
359
|
def method_missing(symbol, *options)
|
244
360
|
guessed_command_name = symbol.to_s.gsub('_','-')
|
245
361
|
if guessed_command_name == "format"
|
@@ -250,21 +366,22 @@ module MiniMagick
|
|
250
366
|
super(symbol, *args)
|
251
367
|
end
|
252
368
|
end
|
253
|
-
|
369
|
+
|
254
370
|
def add(command, *options)
|
255
371
|
push "-#{command}"
|
256
372
|
if options.any?
|
257
373
|
push "\"#{options.join(" ")}\""
|
258
374
|
end
|
259
375
|
end
|
260
|
-
|
376
|
+
|
261
377
|
def push(arg)
|
262
|
-
@args << arg.strip
|
378
|
+
@args << arg.to_s.strip
|
263
379
|
end
|
264
380
|
alias :<< :push
|
265
381
|
|
382
|
+
# @deprecated Please don't use the + method its has been deprecated
|
266
383
|
def +(value)
|
267
|
-
|
384
|
+
warn "Warning: The MiniMagick::ComandBuilder#+ command has been deprecated. Please use c << '+#{value}' instead"
|
268
385
|
push "+#{value}"
|
269
386
|
end
|
270
387
|
end
|
data/test/image_test.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'test/unit'
|
3
|
+
require 'stringio'
|
4
|
+
require 'pathname'
|
3
5
|
require File.expand_path('../../lib/mini_magick', __FILE__)
|
4
6
|
|
5
7
|
#MiniMagick.processor = :gm
|
@@ -10,22 +12,37 @@ class ImageTest < Test::Unit::TestCase
|
|
10
12
|
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
11
13
|
|
12
14
|
SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
|
13
|
-
MINUS_IMAGE_PATH
|
14
|
-
TIFF_IMAGE_PATH
|
15
|
+
MINUS_IMAGE_PATH = CURRENT_DIR + "simple-minus.gif"
|
16
|
+
TIFF_IMAGE_PATH = CURRENT_DIR + "leaves.tiff"
|
15
17
|
NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
|
16
|
-
GIF_WITH_JPG_EXT
|
17
|
-
EXIF_IMAGE_PATH
|
18
|
-
ANIMATION_PATH
|
18
|
+
GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
|
19
|
+
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
|
20
|
+
ANIMATION_PATH = CURRENT_DIR + "animation.gif"
|
19
21
|
|
20
22
|
def test_image_from_blob
|
21
23
|
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
|
22
|
-
image = Image.
|
24
|
+
image = Image.read(f.read)
|
25
|
+
assert image.valid?
|
23
26
|
image.destroy!
|
24
27
|
end
|
25
28
|
end
|
26
29
|
|
27
|
-
def
|
28
|
-
image = Image.
|
30
|
+
def test_image_open
|
31
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
32
|
+
assert image.valid?
|
33
|
+
image.destroy!
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_image_io_reading
|
37
|
+
buffer = StringIO.new(File.read(SIMPLE_IMAGE_PATH))
|
38
|
+
image = Image.read(buffer)
|
39
|
+
image.destroy!
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_image_create
|
43
|
+
image = Image.create do |f|
|
44
|
+
f.write(File.read(SIMPLE_IMAGE_PATH))
|
45
|
+
end
|
29
46
|
image.destroy!
|
30
47
|
end
|
31
48
|
|
@@ -33,6 +50,12 @@ class ImageTest < Test::Unit::TestCase
|
|
33
50
|
image = Image.new(SIMPLE_IMAGE_PATH)
|
34
51
|
image.destroy!
|
35
52
|
end
|
53
|
+
|
54
|
+
def test_remote_image
|
55
|
+
image = Image.open("http://www.google.com/images/logos/logo.png")
|
56
|
+
image.valid?
|
57
|
+
image.destroy!
|
58
|
+
end
|
36
59
|
|
37
60
|
def test_image_write
|
38
61
|
output_path = "output.gif"
|
@@ -52,7 +75,7 @@ class ImageTest < Test::Unit::TestCase
|
|
52
75
|
assert_equal false, image.valid?
|
53
76
|
image.destroy!
|
54
77
|
end
|
55
|
-
|
78
|
+
|
56
79
|
def test_throw_on_openining_not_an_image
|
57
80
|
assert_raise(MiniMagick::Invalid) do
|
58
81
|
image = Image.open(NOT_AN_IMAGE_PATH)
|
@@ -84,7 +107,7 @@ class ImageTest < Test::Unit::TestCase
|
|
84
107
|
end
|
85
108
|
|
86
109
|
def test_image_resize
|
87
|
-
image = Image.
|
110
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
88
111
|
image.resize "20x30!"
|
89
112
|
|
90
113
|
assert_equal 20, image[:width]
|
@@ -94,7 +117,7 @@ class ImageTest < Test::Unit::TestCase
|
|
94
117
|
end
|
95
118
|
|
96
119
|
def test_image_resize_with_minimum
|
97
|
-
image = Image.
|
120
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
98
121
|
original_width, original_height = image[:width], image[:height]
|
99
122
|
image.resize "#{original_width + 10}x#{original_height + 10}>"
|
100
123
|
|
@@ -104,7 +127,7 @@ class ImageTest < Test::Unit::TestCase
|
|
104
127
|
end
|
105
128
|
|
106
129
|
def test_image_combine_options_resize_blur
|
107
|
-
image = Image.
|
130
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
108
131
|
image.combine_options do |c|
|
109
132
|
c.resize "20x30!"
|
110
133
|
c.blur "50"
|
@@ -115,9 +138,9 @@ class ImageTest < Test::Unit::TestCase
|
|
115
138
|
assert_match(/^gif$/i, image[:format])
|
116
139
|
image.destroy!
|
117
140
|
end
|
118
|
-
|
141
|
+
|
119
142
|
def test_image_combine_options_with_filename_with_minusses_in_it
|
120
|
-
image = Image.
|
143
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
121
144
|
background = "#000000"
|
122
145
|
assert_nothing_raised do
|
123
146
|
image.combine_options do |c|
|
@@ -130,44 +153,44 @@ class ImageTest < Test::Unit::TestCase
|
|
130
153
|
end
|
131
154
|
|
132
155
|
def test_exif
|
133
|
-
image = Image.
|
156
|
+
image = Image.open(EXIF_IMAGE_PATH)
|
134
157
|
assert_equal('0220', image["exif:ExifVersion"])
|
135
|
-
image = Image.
|
158
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
136
159
|
assert_equal('', image["EXIF:ExifVersion"])
|
137
160
|
image.destroy!
|
138
161
|
end
|
139
162
|
|
140
163
|
def test_original_at
|
141
|
-
image = Image.
|
164
|
+
image = Image.open(EXIF_IMAGE_PATH)
|
142
165
|
assert_equal(Time.local('2005', '2', '23', '23', '17', '24'), image[:original_at])
|
143
|
-
image = Image.
|
166
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
144
167
|
assert_nil(image[:original_at])
|
145
168
|
image.destroy!
|
146
169
|
end
|
147
170
|
|
148
171
|
def test_tempfile_at_path
|
149
|
-
image = Image.
|
150
|
-
assert_equal image.path, image.tempfile.path
|
172
|
+
image = Image.open(TIFF_IMAGE_PATH)
|
173
|
+
assert_equal image.path, image.instance_eval("@tempfile.path")
|
151
174
|
image.destroy!
|
152
175
|
end
|
153
176
|
|
154
177
|
def test_tempfile_at_path_after_format
|
155
|
-
image = Image.
|
178
|
+
image = Image.open(TIFF_IMAGE_PATH)
|
156
179
|
image.format('png')
|
157
|
-
assert_equal image.path, image.tempfile.path
|
180
|
+
assert_equal image.path, image.instance_eval("@tempfile.path")
|
158
181
|
image.destroy!
|
159
182
|
end
|
160
183
|
|
161
184
|
def test_previous_tempfile_deleted_after_format
|
162
|
-
image = Image.
|
185
|
+
image = Image.open(TIFF_IMAGE_PATH)
|
163
186
|
before = image.path.dup
|
164
187
|
image.format('png')
|
165
188
|
assert !File.exist?(before)
|
166
189
|
image.destroy!
|
167
190
|
end
|
168
|
-
|
191
|
+
|
169
192
|
def test_bad_method_bug
|
170
|
-
image = Image.
|
193
|
+
image = Image.open(TIFF_IMAGE_PATH)
|
171
194
|
begin
|
172
195
|
image.to_blog
|
173
196
|
rescue NoMethodError
|
@@ -177,17 +200,18 @@ class ImageTest < Test::Unit::TestCase
|
|
177
200
|
assert true #we made it this far without error
|
178
201
|
image.destroy!
|
179
202
|
end
|
180
|
-
|
203
|
+
|
181
204
|
def test_simple_composite
|
182
|
-
image = Image.
|
205
|
+
image = Image.open(EXIF_IMAGE_PATH)
|
183
206
|
result = image.composite(Image.open(TIFF_IMAGE_PATH)) do |c|
|
184
207
|
c.gravity "center"
|
185
208
|
end
|
186
209
|
assert `diff -s #{result.path} test/composited.jpg`.include?("identical")
|
187
210
|
end
|
188
|
-
|
211
|
+
|
212
|
+
# http://github.com/probablycorey/mini_magick/issues#issue/8
|
189
213
|
def test_issue_8
|
190
|
-
image = Image.
|
214
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
191
215
|
assert_nothing_raised do
|
192
216
|
image.combine_options do |c|
|
193
217
|
c.sample "50%"
|
@@ -197,8 +221,17 @@ class ImageTest < Test::Unit::TestCase
|
|
197
221
|
image.destroy!
|
198
222
|
end
|
199
223
|
|
224
|
+
# http://github.com/probablycorey/mini_magick/issues#issue/15
|
225
|
+
def test_issue_15
|
226
|
+
image = Image.open(Pathname.new(SIMPLE_IMAGE_PATH))
|
227
|
+
output = Pathname.new("test.gif")
|
228
|
+
image.write(output)
|
229
|
+
ensure
|
230
|
+
FileUtils.rm("test.gif")
|
231
|
+
end
|
232
|
+
|
200
233
|
def test_throw_format_error
|
201
|
-
image = Image.
|
234
|
+
image = Image.open(SIMPLE_IMAGE_PATH)
|
202
235
|
assert_raise MiniMagick::Error do
|
203
236
|
image.combine_options do |c|
|
204
237
|
c.format "png"
|
data/test/leaves.tiff
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 1
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 2
|
8
|
-
-
|
9
|
-
version: "2.
|
7
|
+
- 3
|
8
|
+
version: "2.3"
|
10
9
|
platform: ruby
|
11
10
|
authors:
|
12
11
|
- Corey Johnson
|
@@ -16,7 +15,7 @@ autorequire:
|
|
16
15
|
bindir: bin
|
17
16
|
cert_chain: []
|
18
17
|
|
19
|
-
date: 2010-
|
18
|
+
date: 2010-10-12 00:00:00 +01:00
|
20
19
|
default_executable:
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
@@ -27,7 +26,6 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash: 23
|
31
29
|
segments:
|
32
30
|
- 0
|
33
31
|
- 0
|
@@ -77,7 +75,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
77
75
|
requirements:
|
78
76
|
- - ">="
|
79
77
|
- !ruby/object:Gem::Version
|
80
|
-
hash: 3
|
81
78
|
segments:
|
82
79
|
- 0
|
83
80
|
version: "0"
|
@@ -86,7 +83,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
83
|
requirements:
|
87
84
|
- - ">="
|
88
85
|
- !ruby/object:Gem::Version
|
89
|
-
hash: 3
|
90
86
|
segments:
|
91
87
|
- 0
|
92
88
|
version: "0"
|