mini_magick 3.4 → 3.5.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/MIT-LICENSE +1 -1
- data/lib/mini_magick/version.rb +3 -0
- data/lib/mini_magick.rb +64 -43
- data/test/command_builder_test.rb +24 -5
- data/test/files/composited.jpg +0 -0
- data/test/files/erroneous.jpg +0 -0
- data/test/image_test.rb +27 -10
- data/test/test_helper.rb +11 -10
- metadata +28 -12
- data/README.rdoc +0 -119
- data/VERSION +0 -1
data/MIT-LICENSE
CHANGED
data/lib/mini_magick.rb
CHANGED
@@ -2,6 +2,7 @@ require 'tempfile'
|
|
2
2
|
require 'subexec'
|
3
3
|
require 'stringio'
|
4
4
|
require 'pathname'
|
5
|
+
require 'shellwords'
|
5
6
|
|
6
7
|
module MiniMagick
|
7
8
|
class << self
|
@@ -20,21 +21,21 @@ module MiniMagick
|
|
20
21
|
self.processor = "gm"
|
21
22
|
end
|
22
23
|
end
|
23
|
-
|
24
|
+
|
24
25
|
def image_magick_version
|
25
26
|
@@version ||= Gem::Version.create(`mogrify --version`.split(" ")[2].split("-").first)
|
26
27
|
end
|
27
|
-
|
28
|
+
|
28
29
|
def minimum_image_magick_version
|
29
30
|
@@minimum_version ||= Gem::Version.create("6.6.3")
|
30
31
|
end
|
31
|
-
|
32
|
+
|
32
33
|
def valid_version_installed?
|
33
34
|
image_magick_version >= minimum_image_magick_version
|
34
35
|
end
|
35
36
|
end
|
36
37
|
|
37
|
-
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append authenticate auto-gamma auto-level auto-orient background bench
|
38
|
+
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append attenuate authenticate auto-gamma auto-level auto-orient backdrop background bench bias black-point-compensation black-threshold blend blue-primary blue-shift blur border bordercolor borderwidth brightness-contrast cache caption cdl channel charcoal chop clamp clip clip-mask clip-path clone clut coalesce colorize colormap color-matrix colors colorspace combine comment compose composite compress contrast contrast-stretch convolve crop cycle debug decipher deconstruct define delay delete density depth descend deskew despeckle direction displace display dispose dissimilarity-threshold dissolve distort dither draw duplicate edge emboss encipher encoding endian enhance equalize evaluate evaluate-sequence extent extract family features fft fill filter flatten flip floodfill flop font foreground format frame function fuzz fx gamma gaussian-blur geometry gravity green-primary hald-clut help highlight-color iconGeometry iconic identify ift immutable implode insert intent interlace interpolate interline-spacing interword-spacing kerning label lat layers level level-colors limit linear-stretch linewidth liquid-rescale list log loop lowlight-color magnify map mask mattecolor median metric mode modulate monitor monochrome morph morphology mosaic motion-blur name negate noise normalize opaque ordered-dither orient page paint path pause pen perceptible ping pointsize polaroid poly posterize precision preview print process profile quality quantize quiet radial-blur raise random-threshold red-primary regard-warnings region remap remote render repage resample resize respect-parentheses reverse roll rotate sample sampling-factor scale scene screen seed segment selective-blur separate sepia-tone set shade shadow shared-memory sharpen shave shear sigmoidal-contrast silent size sketch smush snaps solarize sparse-color splice spread statistic stegano stereo stretch strip stroke strokewidth style subimage-search swap swirl synchronize taint text-font texture threshold thumbnail tile tile-offset tint title transform transparent transparent-color transpose transverse treedepth trim type undercolor unique-colors units unsharp update verbose version view vignette virtual-pixel visual watermark wave weight white-point white-threshold window window-group write}
|
38
39
|
|
39
40
|
IMAGE_CREATION_OPERATORS = %w{canvas caption gradient label logo pattern plasma radial radient rose text tile xc }
|
40
41
|
|
@@ -62,7 +63,9 @@ module MiniMagick
|
|
62
63
|
def read(stream, ext = nil)
|
63
64
|
if stream.is_a?(String)
|
64
65
|
stream = StringIO.new(stream)
|
65
|
-
elsif stream.is_a?(
|
66
|
+
elsif stream.is_a?(StringIO)
|
67
|
+
# Do nothing, we want a StringIO-object
|
68
|
+
elsif stream.respond_to? :path
|
66
69
|
if File.respond_to?(:binread)
|
67
70
|
stream = StringIO.new File.binread(stream.path.to_s)
|
68
71
|
else
|
@@ -221,29 +224,29 @@ module MiniMagick
|
|
221
224
|
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
|
222
225
|
case value.to_s
|
223
226
|
when "colorspace"
|
224
|
-
run_command("identify", "-
|
227
|
+
run_command("identify", "-format", format_option("%r"), escaped_path).split("\n")[0].strip
|
225
228
|
when "format"
|
226
|
-
run_command("identify", "-
|
229
|
+
run_command("identify", "-format", format_option("%m"), escaped_path).split("\n")[0]
|
227
230
|
when "height"
|
228
|
-
run_command("identify", "-
|
231
|
+
run_command("identify", "-format", format_option("%h"), escaped_path).split("\n")[0].to_i
|
229
232
|
when "width"
|
230
|
-
run_command("identify", "-
|
233
|
+
run_command("identify", "-format", format_option("%w"), escaped_path).split("\n")[0].to_i
|
231
234
|
when "dimensions"
|
232
|
-
run_command("identify", "-
|
235
|
+
run_command("identify", "-format", format_option("%w %h"), escaped_path).split("\n")[0].split.map{|v|v.to_i}
|
233
236
|
when "size"
|
234
237
|
File.size(@path) # Do this because calling identify -format "%b" on an animated gif fails!
|
235
238
|
when "original_at"
|
236
239
|
# Get the EXIF original capture as a Time object
|
237
240
|
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
|
238
241
|
when /^EXIF\:/i
|
239
|
-
result = run_command('identify', '-
|
242
|
+
result = run_command('identify', '-format', "\"%[#{value}]\"", escaped_path).chop
|
240
243
|
if result.include?(",")
|
241
244
|
read_character_data(result)
|
242
245
|
else
|
243
246
|
result
|
244
247
|
end
|
245
248
|
else
|
246
|
-
run_command('identify', '-
|
249
|
+
run_command('identify', '-format', "\"#{value}\"", escaped_path).split("\n")[0]
|
247
250
|
end
|
248
251
|
end
|
249
252
|
|
@@ -267,13 +270,22 @@ module MiniMagick
|
|
267
270
|
# pages (starting with 0). You can choose which page you want to manipulate. We default to the
|
268
271
|
# first page.
|
269
272
|
#
|
273
|
+
# If you would like to convert between animated formats, pass nil as your
|
274
|
+
# page and ImageMagick will copy all of the pages.
|
275
|
+
#
|
270
276
|
# @param format [String] The target format... like 'jpg', 'gif', 'tiff', etc.
|
271
|
-
# @param page [Integer] If this is an animated gif, say which 'page' you want
|
277
|
+
# @param page [Integer] If this is an animated gif, say which 'page' you want
|
278
|
+
# with an integer. Default 0 will convert only the first page; 'nil' will
|
279
|
+
# convert all pages.
|
272
280
|
# @return [nil]
|
273
281
|
def format(format, page = 0)
|
274
282
|
c = CommandBuilder.new('mogrify', '-format', format)
|
275
283
|
yield c if block_given?
|
276
|
-
|
284
|
+
if page
|
285
|
+
c << @path + "[#{page}]"
|
286
|
+
else
|
287
|
+
c << @path
|
288
|
+
end
|
277
289
|
run(c)
|
278
290
|
|
279
291
|
old_path = @path.dup
|
@@ -281,15 +293,7 @@ module MiniMagick
|
|
281
293
|
File.delete(old_path) if old_path != @path
|
282
294
|
|
283
295
|
unless File.exists?(@path)
|
284
|
-
|
285
|
-
FileUtils.copy_file(@path.sub(".#{format}", "-#{page}.#{format}"), @path)
|
286
|
-
rescue => ex
|
287
|
-
raise MiniMagick::Error, "Unable to format to #{format}; #{ex}" unless File.exist?(@path)
|
288
|
-
end
|
289
|
-
end
|
290
|
-
ensure
|
291
|
-
Dir[@path.sub(/(\.\w+)?$/, "-[0-9]*.#{format}")].each do |fname|
|
292
|
-
File.unlink(fname)
|
296
|
+
raise MiniMagick::Error, "Unable to format to #{format}"
|
293
297
|
end
|
294
298
|
end
|
295
299
|
|
@@ -339,7 +343,7 @@ module MiniMagick
|
|
339
343
|
# Look here to find all the commands (http://www.imagemagick.org/script/mogrify.php)
|
340
344
|
def method_missing(symbol, *args)
|
341
345
|
combine_options do |c|
|
342
|
-
c.
|
346
|
+
c.send(symbol, *args)
|
343
347
|
end
|
344
348
|
end
|
345
349
|
|
@@ -353,10 +357,10 @@ module MiniMagick
|
|
353
357
|
# end
|
354
358
|
#
|
355
359
|
# @yieldparam command [CommandBuilder]
|
356
|
-
def combine_options(tool =
|
360
|
+
def combine_options(tool = "mogrify", &block)
|
357
361
|
c = CommandBuilder.new(tool)
|
358
362
|
|
359
|
-
c << @path if tool ==
|
363
|
+
c << @path if tool.to_s == "convert"
|
360
364
|
block.call(c)
|
361
365
|
c << @path
|
362
366
|
run(c)
|
@@ -394,6 +398,7 @@ module MiniMagick
|
|
394
398
|
# -ping "efficiently determine image characteristics."
|
395
399
|
if command == 'identify'
|
396
400
|
args.unshift '-ping'
|
401
|
+
args.unshift '-quiet' unless MiniMagick.processor.to_s == 'gm'
|
397
402
|
end
|
398
403
|
|
399
404
|
run(CommandBuilder.new(command, *args))
|
@@ -440,31 +445,47 @@ module MiniMagick
|
|
440
445
|
end
|
441
446
|
|
442
447
|
class CommandBuilder
|
443
|
-
|
444
|
-
attr :command
|
448
|
+
attr_reader :args
|
445
449
|
|
446
|
-
def initialize(
|
447
|
-
@
|
450
|
+
def initialize(tool, *options)
|
451
|
+
@tool = tool
|
448
452
|
@args = []
|
449
453
|
options.each { |arg| push(arg) }
|
450
454
|
end
|
451
455
|
|
452
456
|
def command
|
453
|
-
"#{MiniMagick.processor} #{@
|
457
|
+
"#{MiniMagick.processor} #{@tool} #{@args.join(' ')}".strip
|
454
458
|
end
|
455
459
|
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
460
|
+
# Add each mogrify command in both underscore and dash format
|
461
|
+
MOGRIFY_COMMANDS.each do |mogrify_command|
|
462
|
+
|
463
|
+
# Example of what is generated here:
|
464
|
+
#
|
465
|
+
# def auto_orient(*options)
|
466
|
+
# add_command("auto-orient", *options)
|
467
|
+
# self
|
468
|
+
# end
|
469
|
+
# alias_method :"auto-orient", :auto_orient
|
470
|
+
|
471
|
+
dashed_command = mogrify_command.to_s.gsub("_","-")
|
472
|
+
underscored_command = mogrify_command.to_s.gsub("-","_")
|
473
|
+
|
474
|
+
define_method(underscored_command) do |*options|
|
475
|
+
add_command(__method__.to_s.gsub("_","-"), *options)
|
462
476
|
self
|
463
|
-
|
464
|
-
|
477
|
+
end
|
478
|
+
alias_method dashed_command, underscored_command
|
479
|
+
end
|
480
|
+
|
481
|
+
def format(*options)
|
482
|
+
raise Error, "You must call 'format' on the image object directly!"
|
483
|
+
end
|
484
|
+
|
485
|
+
IMAGE_CREATION_OPERATORS.each do |operator|
|
486
|
+
define_method operator do |*options|
|
487
|
+
add_creation_operator(__method__.to_s, *options)
|
465
488
|
self
|
466
|
-
else
|
467
|
-
super(symbol, *args)
|
468
489
|
end
|
469
490
|
end
|
470
491
|
|
@@ -485,9 +506,9 @@ module MiniMagick
|
|
485
506
|
end
|
486
507
|
end
|
487
508
|
end
|
488
|
-
|
509
|
+
|
489
510
|
def escape_string(value)
|
490
|
-
|
511
|
+
Shellwords.escape(value.to_s)
|
491
512
|
end
|
492
513
|
|
493
514
|
def add_creation_operator(command, *options)
|
@@ -6,7 +6,13 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
6
6
|
def test_basic
|
7
7
|
c = CommandBuilder.new("test")
|
8
8
|
c.resize "30x40"
|
9
|
-
assert_equal
|
9
|
+
assert_equal '-resize 30x40', c.args.join(" ")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_full_command
|
13
|
+
c = CommandBuilder.new("test")
|
14
|
+
c.resize "30x40"
|
15
|
+
assert_equal "test -resize 30x40", c.command
|
10
16
|
end
|
11
17
|
|
12
18
|
def test_complicated
|
@@ -14,15 +20,15 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
14
20
|
c.resize "30x40"
|
15
21
|
c.alpha "1 3 4"
|
16
22
|
c.resize "mome fingo"
|
17
|
-
assert_equal
|
23
|
+
assert_equal '-resize 30x40 -alpha 1\ 3\ 4 -resize mome\ fingo', c.args.join(" ")
|
18
24
|
end
|
19
25
|
|
20
26
|
def test_plus_modifier_and_multiple_options
|
21
27
|
c = CommandBuilder.new("test")
|
22
28
|
c.distort.+ 'srt', '0.6 20'
|
23
|
-
assert_equal
|
29
|
+
assert_equal '+distort srt 0.6\ 20', c.args.join(" ")
|
24
30
|
end
|
25
|
-
|
31
|
+
|
26
32
|
def test_valid_command
|
27
33
|
begin
|
28
34
|
c = CommandBuilder.new("test", "path")
|
@@ -38,10 +44,23 @@ class CommandBuilderTest < Test::Unit::TestCase
|
|
38
44
|
c.auto_orient
|
39
45
|
assert_equal "-auto-orient", c.args.join(" ")
|
40
46
|
end
|
41
|
-
|
47
|
+
|
48
|
+
def test_dashed_via_send
|
49
|
+
c = CommandBuilder.new("test")
|
50
|
+
c.send("auto-orient")
|
51
|
+
assert_equal "-auto-orient", c.args.join(" ")
|
52
|
+
end
|
53
|
+
|
42
54
|
def test_canvas
|
43
55
|
c = CommandBuilder.new('test')
|
44
56
|
c.canvas 'black'
|
45
57
|
assert_equal "canvas:black", c.args.join
|
46
58
|
end
|
59
|
+
|
60
|
+
def test_set
|
61
|
+
c = CommandBuilder.new("test")
|
62
|
+
c.set "colorspace RGB"
|
63
|
+
assert_equal 'test -set colorspace\ RGB', c.command
|
64
|
+
end
|
65
|
+
|
47
66
|
end
|
data/test/files/composited.jpg
CHANGED
Binary file
|
Binary file
|
data/test/image_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require 'digest/md5'
|
2
3
|
|
3
4
|
#MiniMagick.processor = :gm
|
4
5
|
|
@@ -14,6 +15,19 @@ class ImageTest < Test::Unit::TestCase
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
|
18
|
+
def test_image_from_tempfile
|
19
|
+
tempfile = Tempfile.new('magick')
|
20
|
+
|
21
|
+
File.open(SIMPLE_IMAGE_PATH, 'rb') do |f|
|
22
|
+
tempfile.write(f.read)
|
23
|
+
tempfile.rewind
|
24
|
+
end
|
25
|
+
|
26
|
+
image = Image.read(tempfile)
|
27
|
+
assert image.valid?
|
28
|
+
image.destroy!
|
29
|
+
end
|
30
|
+
|
17
31
|
def test_image_open
|
18
32
|
image = Image.open(SIMPLE_IMAGE_PATH)
|
19
33
|
assert image.valid?
|
@@ -52,7 +66,7 @@ class ImageTest < Test::Unit::TestCase
|
|
52
66
|
assert image.valid?
|
53
67
|
image.destroy!
|
54
68
|
end
|
55
|
-
|
69
|
+
|
56
70
|
def test_reformat_with_capitalized_extension
|
57
71
|
image = Image.open(CAP_EXT_PATH)
|
58
72
|
image.format "jpg"
|
@@ -111,11 +125,20 @@ class ImageTest < Test::Unit::TestCase
|
|
111
125
|
assert_equal 150, image[:width]
|
112
126
|
assert_equal 55, image[:height]
|
113
127
|
assert_equal [150, 55], image[:dimensions]
|
114
|
-
|
128
|
+
assert_true String == image[:colorspace].class
|
115
129
|
assert_match(/^gif$/i, image[:format])
|
116
130
|
image.destroy!
|
117
131
|
end
|
118
132
|
|
133
|
+
def test_erroneous_image_meta_info
|
134
|
+
image = Image.new(ERRONEOUS_IMAGE_PATH)
|
135
|
+
assert_equal 10, image[:width]
|
136
|
+
assert_equal 10, image[:height]
|
137
|
+
assert_equal [10, 10], image[:dimensions]
|
138
|
+
assert_equal('JPEG', image[:format])
|
139
|
+
image.destroy!
|
140
|
+
end
|
141
|
+
|
119
142
|
def test_tiff
|
120
143
|
image = Image.new(TIFF_IMAGE_PATH)
|
121
144
|
assert_equal "tiff", image[:format].to_s.downcase
|
@@ -231,16 +254,10 @@ class ImageTest < Test::Unit::TestCase
|
|
231
254
|
result = image.composite(Image.open(TIFF_IMAGE_PATH)) do |c|
|
232
255
|
c.gravity "center"
|
233
256
|
end
|
234
|
-
|
257
|
+
assert_true File.exists?(result.path)
|
235
258
|
else
|
236
259
|
puts "Need at least version #{MiniMagick.minimum_image_magick_version} of ImageMagick"
|
237
260
|
end
|
238
|
-
#TODO - need to write test that works cross platform
|
239
|
-
#I thought the following would work but there is a 4 byte difference between the files.
|
240
|
-
#Not sure if it's caused from this test breaking for the right reason though..
|
241
|
-
#assert File.identical?(result.path, COMP_IMAGE_PATH)
|
242
|
-
#This following test will only work on Linux
|
243
|
-
assert `diff -s #{result.path} #{COMP_IMAGE_PATH}`.include?("identical") unless RUBY_PLATFORM =~ /mswin|mingw|cygwin/
|
244
261
|
end
|
245
262
|
|
246
263
|
# http://github.com/probablycorey/mini_magick/issues#issue/8
|
@@ -330,7 +347,7 @@ class ImageTest < Test::Unit::TestCase
|
|
330
347
|
png = Image.open(PNG_PATH)
|
331
348
|
tiff = Image.open(TIFF_IMAGE_PATH)
|
332
349
|
hidden_gif = Image.open(GIF_WITH_JPG_EXT)
|
333
|
-
|
350
|
+
|
334
351
|
assert_equal "image/gif", gif.mime_type
|
335
352
|
assert_equal "image/jpeg", jpeg.mime_type
|
336
353
|
assert_equal "image/png", png.mime_type
|
data/test/test_helper.rb
CHANGED
@@ -7,14 +7,15 @@ require File.expand_path('../../lib/mini_magick', __FILE__)
|
|
7
7
|
|
8
8
|
module MiniMagickTestFiles
|
9
9
|
test_files = File.expand_path(File.dirname(__FILE__) + "/files")
|
10
|
-
SIMPLE_IMAGE_PATH
|
11
|
-
MINUS_IMAGE_PATH
|
12
|
-
TIFF_IMAGE_PATH
|
13
|
-
NOT_AN_IMAGE_PATH
|
14
|
-
GIF_WITH_JPG_EXT
|
15
|
-
EXIF_IMAGE_PATH
|
16
|
-
CAP_EXT_PATH
|
17
|
-
ANIMATION_PATH
|
18
|
-
PNG_PATH
|
19
|
-
COMP_IMAGE_PATH
|
10
|
+
SIMPLE_IMAGE_PATH = test_files + "/simple.gif"
|
11
|
+
MINUS_IMAGE_PATH = test_files + "/simple-minus.gif"
|
12
|
+
TIFF_IMAGE_PATH = test_files + "/leaves (spaced).tiff"
|
13
|
+
NOT_AN_IMAGE_PATH = test_files + "/not_an_image.php"
|
14
|
+
GIF_WITH_JPG_EXT = test_files + "/actually_a_gif.jpg"
|
15
|
+
EXIF_IMAGE_PATH = test_files + "/trogdor.jpg"
|
16
|
+
CAP_EXT_PATH = test_files + "/trogdor_capitalized.JPG"
|
17
|
+
ANIMATION_PATH = test_files + "/animation.gif"
|
18
|
+
PNG_PATH = test_files + "/png.png"
|
19
|
+
COMP_IMAGE_PATH = test_files + "/composited.jpg"
|
20
|
+
ERRONEOUS_IMAGE_PATH = test_files + "/erroneous.jpg"
|
20
21
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mini_magick
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.5.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,11 +11,11 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2013-02-14 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: subexec
|
18
|
-
requirement:
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
19
|
none: false
|
20
20
|
requirements:
|
21
21
|
- - ~>
|
@@ -23,10 +23,15 @@ dependencies:
|
|
23
23
|
version: 0.2.1
|
24
24
|
type: :runtime
|
25
25
|
prerelease: false
|
26
|
-
version_requirements:
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ~>
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: 0.2.1
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
33
|
name: rake
|
29
|
-
requirement:
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
30
35
|
none: false
|
31
36
|
requirements:
|
32
37
|
- - ! '>='
|
@@ -34,10 +39,15 @@ dependencies:
|
|
34
39
|
version: '0'
|
35
40
|
type: :development
|
36
41
|
prerelease: false
|
37
|
-
version_requirements:
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
38
48
|
- !ruby/object:Gem::Dependency
|
39
49
|
name: test-unit
|
40
|
-
requirement:
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
41
51
|
none: false
|
42
52
|
requirements:
|
43
53
|
- - ! '>='
|
@@ -45,7 +55,12 @@ dependencies:
|
|
45
55
|
version: '0'
|
46
56
|
type: :development
|
47
57
|
prerelease: false
|
48
|
-
version_requirements:
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
49
64
|
description: ''
|
50
65
|
email:
|
51
66
|
- probablycorey@gmail.com
|
@@ -55,16 +70,16 @@ executables: []
|
|
55
70
|
extensions: []
|
56
71
|
extra_rdoc_files: []
|
57
72
|
files:
|
58
|
-
- README.rdoc
|
59
|
-
- VERSION
|
60
73
|
- MIT-LICENSE
|
61
74
|
- Rakefile
|
62
75
|
- lib/mini_gmagick.rb
|
76
|
+
- lib/mini_magick/version.rb
|
63
77
|
- lib/mini_magick.rb
|
64
78
|
- test/command_builder_test.rb
|
65
79
|
- test/files/actually_a_gif.jpg
|
66
80
|
- test/files/animation.gif
|
67
81
|
- test/files/composited.jpg
|
82
|
+
- test/files/erroneous.jpg
|
68
83
|
- test/files/leaves (spaced).tiff
|
69
84
|
- test/files/not_an_image.php
|
70
85
|
- test/files/png.png
|
@@ -76,7 +91,7 @@ files:
|
|
76
91
|
- test/leaves (spaced).tiff
|
77
92
|
- test/test_helper.rb
|
78
93
|
- test/trogdor_capitalized.JPG
|
79
|
-
homepage:
|
94
|
+
homepage: https://github.com/minimagick/minimagick
|
80
95
|
licenses: []
|
81
96
|
post_install_message:
|
82
97
|
rdoc_options: []
|
@@ -96,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
111
|
version: '0'
|
97
112
|
requirements: []
|
98
113
|
rubyforge_project:
|
99
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.23
|
100
115
|
signing_key:
|
101
116
|
specification_version: 3
|
102
117
|
summary: Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick
|
@@ -105,6 +120,7 @@ test_files:
|
|
105
120
|
- test/files/actually_a_gif.jpg
|
106
121
|
- test/files/animation.gif
|
107
122
|
- test/files/composited.jpg
|
123
|
+
- test/files/erroneous.jpg
|
108
124
|
- test/files/leaves (spaced).tiff
|
109
125
|
- test/files/not_an_image.php
|
110
126
|
- test/files/png.png
|
data/README.rdoc
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
= MiniMagick
|
2
|
-
|
3
|
-
A ruby wrapper for ImageMagick or GraphicsMagick command line.
|
4
|
-
|
5
|
-
Tested on both Ruby 1.9.2 and Ruby 1.8.7.
|
6
|
-
|
7
|
-
== Why?
|
8
|
-
|
9
|
-
I was using RMagick and loving it, but it was eating up huge amounts
|
10
|
-
of memory. A simple script like this...
|
11
|
-
|
12
|
-
Magick::read("image.jpg") do |f|
|
13
|
-
f.write("manipulated.jpg")
|
14
|
-
end
|
15
|
-
|
16
|
-
...would use over 100 Megs of Ram. On my local machine this wasn't a
|
17
|
-
problem, but on my hosting server the ruby apps would crash because of
|
18
|
-
their 100 Meg memory limit.
|
19
|
-
|
20
|
-
|
21
|
-
== Solution!
|
22
|
-
|
23
|
-
Using MiniMagick the ruby processes memory remains small (it spawns
|
24
|
-
ImageMagick's command line program mogrify which takes up some memory
|
25
|
-
as well, but is much smaller compared to RMagick)
|
26
|
-
|
27
|
-
MiniMagick gives you access to all the commandline options ImageMagick
|
28
|
-
has (Found here http://www.imagemagick.org/script/mogrify.php)
|
29
|
-
|
30
|
-
|
31
|
-
== Examples
|
32
|
-
|
33
|
-
Want to make a thumbnail from a file...
|
34
|
-
|
35
|
-
image = MiniMagick::Image.open("input.jpg")
|
36
|
-
image.resize "100x100"
|
37
|
-
image.write "output.jpg"
|
38
|
-
|
39
|
-
Want to make a thumbnail from a blob...
|
40
|
-
|
41
|
-
image = MiniMagick::Image.read(blob)
|
42
|
-
image.resize "100x100"
|
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"
|
55
|
-
|
56
|
-
Need to combine several options?
|
57
|
-
|
58
|
-
image = MiniMagick::Image.open("input.jpg")
|
59
|
-
image.combine_options do |c|
|
60
|
-
c.sample "50%"
|
61
|
-
c.rotate "-90>"
|
62
|
-
end
|
63
|
-
image.write "output.jpg"
|
64
|
-
|
65
|
-
Want to composite two images? Super easy! (Aka, put a watermark on!)
|
66
|
-
|
67
|
-
image = Image.open("original.png")
|
68
|
-
result = image.composite(Image.open("watermark.png", "jpg") do |c|
|
69
|
-
c.gravity "center"
|
70
|
-
end
|
71
|
-
result.write "my_output_file.jpg"
|
72
|
-
|
73
|
-
Want to manipulate an image at its source (You won't have to write it
|
74
|
-
out because the transformations are done on that file)
|
75
|
-
|
76
|
-
image = MiniMagick::Image.new("input.jpg")
|
77
|
-
image.resize "100x100"
|
78
|
-
|
79
|
-
Want to get some meta-information out?
|
80
|
-
|
81
|
-
image = MiniMagick::Image.open("input.jpg")
|
82
|
-
image[:width] # will get the width (you can also use :height and :format)
|
83
|
-
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
|
84
|
-
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command
|
85
|
-
|
86
|
-
Want to use an internal image creation to create a big black square?
|
87
|
-
|
88
|
-
image = MiniMagick::Image.create 'jpg', false do |c|
|
89
|
-
c.size '1024x1024' # creates image option '-size 1024x1024'
|
90
|
-
c.canvas 'black' # creates image creation operator 'canvas:black'
|
91
|
-
end
|
92
|
-
|
93
|
-
For more on the format command see
|
94
|
-
http://www.imagemagick.org/script/command-line-options.php#format
|
95
|
-
|
96
|
-
|
97
|
-
== Windows Users
|
98
|
-
|
99
|
-
When passing in a blob or IOStream, Windows users need to make sure they read the file in as binary.
|
100
|
-
|
101
|
-
#This way works on Windows
|
102
|
-
buffer = StringIO.new(File.open(IMAGE_PATH,"rb") { |f| f.read })
|
103
|
-
MiniMagick::Image.read(buffer)
|
104
|
-
|
105
|
-
#You may run into problems doing it this way
|
106
|
-
buffer = StringIO.new(File.read(IMAGE_PATH))
|
107
|
-
|
108
|
-
|
109
|
-
== Using GraphicsMagick
|
110
|
-
|
111
|
-
Simply set
|
112
|
-
|
113
|
-
MiniMagick.processor = :gm
|
114
|
-
|
115
|
-
And you are sorted.
|
116
|
-
|
117
|
-
== Requirements
|
118
|
-
|
119
|
-
You must have ImageMagick or GraphicsMagick installed.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
3.4
|