mini_magick 1.2.3 → 1.2.5
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/.gitignore +1 -0
- data/MIT-LICENSE +0 -0
- data/README.rdoc +72 -0
- data/Rakefile +66 -15
- data/VERSION +1 -0
- data/lib/image_temp_file.rb +3 -7
- data/lib/mini_magick.rb +55 -22
- data/mini_magick.gemspec +55 -0
- data/test/actually_a_gif.jpg +0 -0
- data/test/animation.gif +0 -0
- data/test/command_builder_test.rb +20 -0
- data/test/image_temp_file_test.rb +17 -0
- data/test/{test_mini_magick_test.rb → image_test.rb} +56 -36
- data/test/leaves.tiff +0 -0
- data/test/not_an_image.php +0 -0
- data/test/simple.gif +0 -0
- data/test/trogdor.jpg +0 -0
- metadata +53 -53
- data/History.txt +0 -11
- data/Manifest.txt +0 -14
- data/README.txt +0 -101
- data/init.rb +0 -2
- data/test/test_image_temp_file.rb +0 -14
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/pkg
|
data/MIT-LICENSE
CHANGED
File without changes
|
data/README.rdoc
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
= MiniMagick
|
2
|
+
|
3
|
+
A ruby wrapper for ImageMagick command line.
|
4
|
+
|
5
|
+
|
6
|
+
== Why?
|
7
|
+
|
8
|
+
I was using RMagick and loving it, but it was eating up huge amounts
|
9
|
+
of memory. A simple script like this...
|
10
|
+
|
11
|
+
Magick::read("image.jpg") do |f|
|
12
|
+
f.write("manipulated.jpg")
|
13
|
+
end
|
14
|
+
|
15
|
+
...would use over 100 Megs of Ram. On my local machine this wasn't a
|
16
|
+
problem, but on my hosting server the ruby apps would crash because of
|
17
|
+
their 100 Meg memory limit.
|
18
|
+
|
19
|
+
|
20
|
+
== Solution!
|
21
|
+
|
22
|
+
Using MiniMagick the ruby processes memory remains small (it spawns
|
23
|
+
ImageMagick's command line program mogrify which takes up some memory
|
24
|
+
as well, but is much smaller compared to RMagick)
|
25
|
+
|
26
|
+
MiniMagick gives you access to all the commandline options ImageMagick
|
27
|
+
has (Found here http://www.imagemagick.org/script/mogrify.php)
|
28
|
+
|
29
|
+
|
30
|
+
== Examples
|
31
|
+
|
32
|
+
Want to make a thumbnail from a file...
|
33
|
+
|
34
|
+
image = MiniMagick::Image.from_file("input.jpg")
|
35
|
+
image.resize "100x100"
|
36
|
+
image.write("output.jpg")
|
37
|
+
|
38
|
+
Want to make a thumbnail from a blob...
|
39
|
+
|
40
|
+
image = MiniMagick::Image.from_blob(blob)
|
41
|
+
image.resize "100x100"
|
42
|
+
image.write("output.jpg")
|
43
|
+
|
44
|
+
Need to combine several options?
|
45
|
+
|
46
|
+
image = MiniMagick::Image.from_file("input.jpg")
|
47
|
+
image.combine_options do |c|
|
48
|
+
c.sample "50%"
|
49
|
+
c.rotate "-90>"
|
50
|
+
end
|
51
|
+
image.write("output.jpg")
|
52
|
+
|
53
|
+
Want to manipulate an image at its source (You won't have to write it
|
54
|
+
out because the transformations are done on that file)
|
55
|
+
|
56
|
+
image = MiniMagick::Image.new("input.jpg")
|
57
|
+
image.resize "100x100"
|
58
|
+
|
59
|
+
Want to get some meta-information out?
|
60
|
+
|
61
|
+
image = MiniMagick::Image.from_file("input.jpg")
|
62
|
+
image[:width] # will get the width (you can also use :height and :format)
|
63
|
+
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
|
64
|
+
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command
|
65
|
+
|
66
|
+
For more on the format command see
|
67
|
+
http://www.imagemagick.org/script/command-line-options.php#format
|
68
|
+
|
69
|
+
|
70
|
+
== Requirements
|
71
|
+
|
72
|
+
You must have ImageMagick installed.
|
data/Rakefile
CHANGED
@@ -1,17 +1,68 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require '
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
$:.unshift(File.dirname(__FILE__) + "/lib")
|
6
|
+
require 'mini_magick'
|
7
|
+
|
8
|
+
desc 'Default: run unit tests.'
|
9
|
+
task :default => :test
|
10
|
+
|
11
|
+
desc 'Test the mini_magick plugin.'
|
12
|
+
Rake::TestTask.new(:test) do |t|
|
13
|
+
t.libs << 'lib'
|
14
|
+
t.pattern = 'test/**/*_test.rb'
|
15
|
+
t.verbose = true
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
+
desc 'Generate documentation for the mini_magick plugin.'
|
19
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
20
|
+
rdoc.rdoc_dir = 'rdoc'
|
21
|
+
rdoc.title = 'MiniMagick'
|
22
|
+
rdoc.options << '--line-numbers'
|
23
|
+
rdoc.options << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README.rdoc')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
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."
|
68
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.2.5
|
data/lib/image_temp_file.rb
CHANGED
@@ -2,12 +2,8 @@ require "tempfile"
|
|
2
2
|
|
3
3
|
module MiniMagick
|
4
4
|
class ImageTempFile < Tempfile
|
5
|
-
def make_tmpname(
|
6
|
-
|
7
|
-
ext = File.extname(basename)
|
8
|
-
|
9
|
-
# force hyphens instead of periods in name
|
10
|
-
sprintf('%s%d-%d%s', File.basename(basename, ext), $$, n, ext)
|
5
|
+
def make_tmpname(ext, n)
|
6
|
+
'mini_magick%d-%d%s' % [$$, n, ext ? ".#{ext}" : '']
|
11
7
|
end
|
12
8
|
end
|
13
|
-
end
|
9
|
+
end
|
data/lib/mini_magick.rb
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "stringio"
|
3
3
|
require "fileutils"
|
4
|
+
require "open3"
|
4
5
|
|
5
6
|
require File.join(File.dirname(__FILE__), '/image_temp_file')
|
6
7
|
|
7
8
|
module MiniMagick
|
8
9
|
class MiniMagickError < RuntimeError; end
|
9
10
|
|
10
|
-
VERSION = '1.2.3'
|
11
|
-
|
12
11
|
class Image
|
13
12
|
attr :path
|
14
13
|
attr :tempfile
|
@@ -16,25 +15,26 @@ module MiniMagick
|
|
16
15
|
|
17
16
|
# Class Methods
|
18
17
|
# -------------
|
19
|
-
class <<self
|
20
|
-
def from_blob(blob,
|
18
|
+
class << self
|
19
|
+
def from_blob(blob, ext = nil)
|
21
20
|
begin
|
22
|
-
tempfile = ImageTempFile.new(
|
21
|
+
tempfile = ImageTempFile.new(ext)
|
23
22
|
tempfile.binmode
|
24
23
|
tempfile.write(blob)
|
25
24
|
ensure
|
26
|
-
tempfile.close
|
25
|
+
tempfile.close if tempfile
|
27
26
|
end
|
28
|
-
|
27
|
+
|
29
28
|
return self.new(tempfile.path, tempfile)
|
30
29
|
end
|
31
30
|
|
32
31
|
# Use this if you don't want to overwrite the image file
|
33
|
-
def
|
32
|
+
def open(image_path)
|
34
33
|
File.open(image_path, "rb") do |f|
|
35
34
|
self.from_blob(f.read, File.extname(image_path))
|
36
35
|
end
|
37
36
|
end
|
37
|
+
alias_method :from_file, :open
|
38
38
|
end
|
39
39
|
|
40
40
|
# Instance Methods
|
@@ -57,6 +57,10 @@ module MiniMagick
|
|
57
57
|
run_command("identify", "-format", format_option("%h"), @path).split("\n")[0].to_i
|
58
58
|
when "width"
|
59
59
|
run_command("identify", "-format", format_option("%w"), @path).split("\n")[0].to_i
|
60
|
+
when "dimensions"
|
61
|
+
run_command("identify", "-format", format_option("%w %h"), @path).split("\n")[0].split.map{|v|v.to_i}
|
62
|
+
when "size"
|
63
|
+
File.size(@path) # Do this because calling identify -format "%b" on an animated gif fails!
|
60
64
|
when "original_at"
|
61
65
|
# Get the EXIF original capture as a Time object
|
62
66
|
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
|
@@ -67,12 +71,33 @@ module MiniMagick
|
|
67
71
|
end
|
68
72
|
end
|
69
73
|
|
74
|
+
# Sends raw commands to imagemagick's mogrify command. The image path is automatically appended to the command
|
75
|
+
def <<(*args)
|
76
|
+
run_command("mogrify", *args << @path)
|
77
|
+
end
|
78
|
+
|
70
79
|
# This is a 'special' command because it needs to change @path to reflect the new extension
|
71
|
-
|
80
|
+
# Formatting an animation into a non-animated type will result in ImageMagick creating multiple
|
81
|
+
# pages (starting with 0). You can choose which page you want to manipulate. We default to the
|
82
|
+
# first page.
|
83
|
+
def format(format, page=0)
|
72
84
|
run_command("mogrify", "-format", format, @path)
|
73
|
-
|
74
|
-
|
75
|
-
|
85
|
+
|
86
|
+
old_path = @path.dup
|
87
|
+
@path.sub!(/(\.\w+)?$/, ".#{format}")
|
88
|
+
File.delete(old_path) unless old_path == @path
|
89
|
+
|
90
|
+
unless File.exists?(@path)
|
91
|
+
begin
|
92
|
+
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
|
+
end
|
96
|
+
end
|
97
|
+
ensure
|
98
|
+
Dir[@path.sub(/(\.\w+)?$/, "-[0-9]*.#{format}")].each do |fname|
|
99
|
+
File.unlink(fname)
|
100
|
+
end
|
76
101
|
end
|
77
102
|
|
78
103
|
# Writes the temporary image that we are using for processing to the output path
|
@@ -83,7 +108,11 @@ module MiniMagick
|
|
83
108
|
|
84
109
|
# Give you raw data back
|
85
110
|
def to_blob
|
86
|
-
File.
|
111
|
+
f = File.new @path
|
112
|
+
f.binmode
|
113
|
+
f.read
|
114
|
+
ensure
|
115
|
+
f.close if f
|
87
116
|
end
|
88
117
|
|
89
118
|
# If an unknown method is called then it is sent through the morgrify program
|
@@ -112,18 +141,22 @@ module MiniMagick
|
|
112
141
|
end
|
113
142
|
|
114
143
|
def run_command(command, *args)
|
115
|
-
args.collect! do |arg|
|
116
|
-
|
117
|
-
|
118
|
-
|
144
|
+
args.collect! do |arg|
|
145
|
+
# args can contain characters like '>' so we must escape them, but don't quote switches
|
146
|
+
if arg !~ /^\+|\-/
|
147
|
+
"\"#{arg}\""
|
148
|
+
else
|
149
|
+
arg.to_s
|
150
|
+
end
|
119
151
|
end
|
120
152
|
|
121
|
-
|
153
|
+
command = "#{command} #{args.join(' ')}"
|
154
|
+
output = `#{command} 2>&1`
|
122
155
|
|
123
|
-
if
|
124
|
-
raise MiniMagickError, "ImageMagick command (#{command} #{
|
156
|
+
if $?.exitstatus != 0
|
157
|
+
raise MiniMagickError, "ImageMagick command (#{command.inspect}) failed: #{{:status_code => $?, :output => output}.inspect}"
|
125
158
|
else
|
126
|
-
|
159
|
+
output
|
127
160
|
end
|
128
161
|
end
|
129
162
|
end
|
@@ -139,7 +172,7 @@ module MiniMagick
|
|
139
172
|
@args << "-#{symbol}"
|
140
173
|
@args += args
|
141
174
|
end
|
142
|
-
|
175
|
+
|
143
176
|
def +(value)
|
144
177
|
@args << "+#{value}"
|
145
178
|
end
|
data/mini_magick.gemspec
ADDED
@@ -0,0 +1,55 @@
|
|
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
|
data/test/actually_a_gif.jpg
CHANGED
File without changes
|
data/test/animation.gif
ADDED
Binary file
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/mini_magick')
|
3
|
+
|
4
|
+
class CommandBuilderTest < Test::Unit::TestCase
|
5
|
+
include MiniMagick
|
6
|
+
|
7
|
+
def test_basic
|
8
|
+
c = CommandBuilder.new
|
9
|
+
c.resize "30x40"
|
10
|
+
assert_equal "-resize 30x40", c.args.join(" ")
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_complicated
|
14
|
+
c = CommandBuilder.new
|
15
|
+
c.resize "30x40"
|
16
|
+
c.input 1, 3, 4
|
17
|
+
c.lingo "mome fingo"
|
18
|
+
assert_equal "-resize 30x40 -input 1 3 4 -lingo mome fingo", c.args.join(" ")
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
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
|
@@ -3,66 +3,79 @@ require File.join(File.dirname(__FILE__), '../lib/mini_magick')
|
|
3
3
|
|
4
4
|
class ImageTest < Test::Unit::TestCase
|
5
5
|
include MiniMagick
|
6
|
-
|
6
|
+
|
7
7
|
CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
|
8
8
|
|
9
9
|
SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
|
10
|
-
TIFF_IMAGE_PATH = CURRENT_DIR + "
|
10
|
+
TIFF_IMAGE_PATH = CURRENT_DIR + "leaves.tiff"
|
11
11
|
NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
|
12
12
|
GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
|
13
13
|
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
|
14
|
-
|
14
|
+
ANIMATION_PATH = CURRENT_DIR + "animation.gif"
|
15
|
+
|
15
16
|
def test_image_from_blob
|
16
17
|
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
|
17
18
|
image = Image.from_blob(f.read)
|
18
19
|
end
|
19
20
|
end
|
20
|
-
|
21
|
+
|
21
22
|
def test_image_from_file
|
22
23
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
23
24
|
end
|
24
|
-
|
25
|
+
|
25
26
|
def test_image_new
|
26
27
|
image = Image.new(SIMPLE_IMAGE_PATH)
|
27
28
|
end
|
28
|
-
|
29
|
+
|
29
30
|
def test_image_write
|
30
31
|
output_path = "output.gif"
|
31
32
|
begin
|
32
33
|
image = Image.new(SIMPLE_IMAGE_PATH)
|
33
34
|
image.write output_path
|
34
|
-
|
35
|
+
|
35
36
|
assert File.exists?(output_path)
|
36
37
|
ensure
|
37
38
|
File.delete output_path
|
38
39
|
end
|
39
40
|
end
|
40
|
-
|
41
|
+
|
41
42
|
def test_not_an_image
|
42
43
|
assert_raise(MiniMagickError) do
|
43
44
|
image = Image.new(NOT_AN_IMAGE_PATH)
|
44
45
|
end
|
45
46
|
end
|
46
|
-
|
47
|
+
|
47
48
|
def test_image_meta_info
|
48
49
|
image = Image.new(SIMPLE_IMAGE_PATH)
|
49
50
|
assert_equal 150, image[:width]
|
50
51
|
assert_equal 55, image[:height]
|
52
|
+
assert_equal [150, 55], image[:dimensions]
|
51
53
|
assert_match(/^gif$/i, image[:format])
|
52
54
|
end
|
53
55
|
|
54
56
|
def test_tiff
|
55
|
-
image = Image.new(TIFF_IMAGE_PATH)
|
57
|
+
image = Image.new(TIFF_IMAGE_PATH)
|
56
58
|
assert_equal "tiff", image[:format].downcase
|
57
|
-
assert_equal
|
58
|
-
assert_equal
|
59
|
+
assert_equal 295, image[:width]
|
60
|
+
assert_equal 242, image[:height]
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_animation_pages
|
64
|
+
image = Image.from_file(ANIMATION_PATH)
|
65
|
+
image.format "png", 0
|
66
|
+
assert_equal "png", image[:format].downcase
|
59
67
|
end
|
60
|
-
|
68
|
+
|
69
|
+
def test_animation_size
|
70
|
+
image = Image.from_file(ANIMATION_PATH)
|
71
|
+
assert_equal image[:size], 76631
|
72
|
+
end
|
73
|
+
|
61
74
|
def test_gif_with_jpg_format
|
62
|
-
image = Image.new(GIF_WITH_JPG_EXT)
|
75
|
+
image = Image.new(GIF_WITH_JPG_EXT)
|
63
76
|
assert_equal "gif", image[:format].downcase
|
64
77
|
end
|
65
|
-
|
78
|
+
|
66
79
|
def test_image_resize
|
67
80
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
68
81
|
image.resize "20x30!"
|
@@ -70,8 +83,8 @@ class ImageTest < Test::Unit::TestCase
|
|
70
83
|
assert_equal 20, image[:width]
|
71
84
|
assert_equal 30, image[:height]
|
72
85
|
assert_match(/^gif$/i, image[:format])
|
73
|
-
end
|
74
|
-
|
86
|
+
end
|
87
|
+
|
75
88
|
def test_image_resize_with_minimum
|
76
89
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
77
90
|
original_width, original_height = image[:width], image[:height]
|
@@ -80,7 +93,7 @@ class ImageTest < Test::Unit::TestCase
|
|
80
93
|
assert_equal original_width, image[:width]
|
81
94
|
assert_equal original_height, image[:height]
|
82
95
|
end
|
83
|
-
|
96
|
+
|
84
97
|
def test_image_combine_options_resize_blur
|
85
98
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
86
99
|
image.combine_options do |c|
|
@@ -92,36 +105,43 @@ class ImageTest < Test::Unit::TestCase
|
|
92
105
|
assert_equal 30, image[:height]
|
93
106
|
assert_match(/^gif$/i, image[:format])
|
94
107
|
end
|
95
|
-
|
108
|
+
|
96
109
|
def test_exif
|
97
110
|
image = Image.from_file(EXIF_IMAGE_PATH)
|
98
111
|
assert_equal('0220', image["exif:ExifVersion"])
|
99
112
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
100
113
|
assert_equal('', image["EXIF:ExifVersion"])
|
101
114
|
end
|
102
|
-
|
115
|
+
|
103
116
|
def test_original_at
|
104
117
|
image = Image.from_file(EXIF_IMAGE_PATH)
|
105
118
|
assert_equal(Time.local('2005', '2', '23', '23', '17', '24'), image[:original_at])
|
106
119
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
107
120
|
assert_nil(image[:original_at])
|
108
121
|
end
|
109
|
-
end
|
110
122
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
123
|
+
def test_tempfile_at_path
|
124
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
125
|
+
assert_equal image.path, image.tempfile.path
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_tempfile_at_path_after_format
|
129
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
130
|
+
image.format('png')
|
131
|
+
assert_equal image.path, image.tempfile.path
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_previous_tempfile_deleted_after_format
|
135
|
+
image = Image.from_file(TIFF_IMAGE_PATH)
|
136
|
+
before = image.path.dup
|
137
|
+
image.format('png')
|
138
|
+
assert !File.exist?(before)
|
139
|
+
end
|
140
|
+
|
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
|
126
146
|
end
|
127
147
|
end
|
data/test/leaves.tiff
ADDED
Binary file
|
data/test/not_an_image.php
CHANGED
File without changes
|
data/test/simple.gif
CHANGED
File without changes
|
data/test/trogdor.jpg
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,71 +1,71 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0.1
|
3
|
-
specification_version: 1
|
4
2
|
name: mini_magick
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.2.
|
7
|
-
date: 2007-06-15 00:00:00 -04:00
|
8
|
-
summary: A simple image manipulation library based on ImageMagick.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: probablycorey+ruby@gmail.com
|
12
|
-
homepage: http://www.zenspider.com/ZSS/Products/mini_magick/
|
13
|
-
rubyforge_project: mini_magick
|
14
|
-
description: "- Why? I was using RMagick and loving it, but it was eating up huge amounts of memory. A simple script like this... Magick::read(\"image.jpg\") do |f| f.write(\"manipulated.jpg\") end ...would use over 100 Megs of Ram. On my local machine this wasn't a problem, but on my hosting server the ruby apps would crash because of their 100 Meg memory limit."
|
15
|
-
autorequire:
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: true
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 1.2.5
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Corey Johnson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-27 00:00:00 +00:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: probablycorey@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
31
24
|
files:
|
25
|
+
- .gitignore
|
32
26
|
- MIT-LICENSE
|
33
|
-
-
|
34
|
-
- Manifest.txt
|
35
|
-
- README.txt
|
27
|
+
- README.rdoc
|
36
28
|
- Rakefile
|
37
|
-
-
|
29
|
+
- VERSION
|
38
30
|
- lib/image_temp_file.rb
|
39
31
|
- lib/mini_magick.rb
|
32
|
+
- mini_magick.gemspec
|
40
33
|
- test/actually_a_gif.jpg
|
34
|
+
- test/animation.gif
|
35
|
+
- test/command_builder_test.rb
|
36
|
+
- test/image_temp_file_test.rb
|
37
|
+
- test/image_test.rb
|
38
|
+
- test/leaves.tiff
|
41
39
|
- test/not_an_image.php
|
42
40
|
- test/simple.gif
|
43
|
-
- test/test_image_temp_file.rb
|
44
|
-
- test/test_mini_magick_test.rb
|
45
41
|
- test/trogdor.jpg
|
46
|
-
|
47
|
-
|
48
|
-
|
42
|
+
has_rdoc: true
|
43
|
+
homepage: http://github.com/probablycorey/mini_magick
|
44
|
+
post_install_message:
|
49
45
|
rdoc_options:
|
50
|
-
- --
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
46
|
+
- --charset=UTF-8
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: "0"
|
54
|
+
version:
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: "0"
|
60
|
+
version:
|
60
61
|
requirements: []
|
61
62
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
version:
|
63
|
+
rubyforge_project: mini-magick
|
64
|
+
rubygems_version: 1.3.1
|
65
|
+
signing_key:
|
66
|
+
specification_version: 2
|
67
|
+
summary: Manipulate images with minimal use of memory.
|
68
|
+
test_files:
|
69
|
+
- test/command_builder_test.rb
|
70
|
+
- test/image_temp_file_test.rb
|
71
|
+
- test/image_test.rb
|
data/History.txt
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
== 1.2.2 / 2007-06-01
|
2
|
-
|
3
|
-
# 1.) all image commands return the image object (The output of the last command is saved in @output)
|
4
|
-
# 2.) identify doesn't trip over strangley named files
|
5
|
-
# 3.) TempFile uses file extention now (Thanks http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions)
|
6
|
-
# 4.) identify commands escape output path correctly
|
7
|
-
|
8
|
-
== 1.2.3 / 2007-06-15
|
9
|
-
|
10
|
-
# 1.) Image::from_file doesn't drop the file extension anymore, it and use the image_temp_file correctly
|
11
|
-
# 4.) TempFiles are stored as an instance variable in Image instances so they don't get cleaned up prematurely via garbage collection
|
data/Manifest.txt
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
MIT-LICENSE
|
2
|
-
History.txt
|
3
|
-
Manifest.txt
|
4
|
-
README.txt
|
5
|
-
Rakefile
|
6
|
-
init.rb
|
7
|
-
lib/image_temp_file.rb
|
8
|
-
lib/mini_magick.rb
|
9
|
-
test/actually_a_gif.jpg
|
10
|
-
test/not_an_image.php
|
11
|
-
test/simple.gif
|
12
|
-
test/test_image_temp_file.rb
|
13
|
-
test/test_mini_magick_test.rb
|
14
|
-
test/trogdor.jpg
|
data/README.txt
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
mini_magick
|
2
|
-
by Coery Johnson
|
3
|
-
FIX (url)
|
4
|
-
|
5
|
-
== DESCRIPTION:
|
6
|
-
|
7
|
-
A ruby wrapper for ImageMagick command line.
|
8
|
-
|
9
|
-
- Why?
|
10
|
-
|
11
|
-
I was using RMagick and loving it, but it was eating up huge amounts of memory. A simple script like this...
|
12
|
-
|
13
|
-
Magick::read("image.jpg") do |f|
|
14
|
-
f.write("manipulated.jpg")
|
15
|
-
end
|
16
|
-
|
17
|
-
...would use over 100 Megs of Ram. On my local machine this wasn't a problem, but on my hosting server the ruby apps would crash because of their 100 Meg memory limit.
|
18
|
-
|
19
|
-
- Solution!
|
20
|
-
|
21
|
-
Using MiniMagick the ruby processes memory remains small (it spawns ImageMagick's command line program mogrify which takes up some memory as well, but is much smaller compared to RMagick)
|
22
|
-
|
23
|
-
|
24
|
-
== FEATURES/PROBLEMS:
|
25
|
-
|
26
|
-
MiniMagick gives you access to all the commandline options ImageMagick has (Found here http://www.imagemagick.org/script/mogrify.php)
|
27
|
-
|
28
|
-
== SYNOPSIS:
|
29
|
-
|
30
|
-
Want to make a thumbnail from a file...
|
31
|
-
|
32
|
-
image = MiniMagick::Image.from_file("input.jpg")
|
33
|
-
image.resize "100x100"
|
34
|
-
image.write("output.jpg")
|
35
|
-
|
36
|
-
Want to make a thumbnail from a blob...
|
37
|
-
|
38
|
-
image = MiniMagick::Image.from_blob(blob)
|
39
|
-
image.resize "100x100"
|
40
|
-
image.write("output.jpg")
|
41
|
-
|
42
|
-
Need to combine several options?
|
43
|
-
|
44
|
-
image = MiniMagick::Image.from_file("input.jpg")
|
45
|
-
image.combine_options do |c|
|
46
|
-
c.sample "50%"
|
47
|
-
c.rotate "-90>"
|
48
|
-
end
|
49
|
-
image.write("output.jpg")
|
50
|
-
|
51
|
-
Want to manipulate an image at its source (You won't have to write it out because the transformations are done on that file)
|
52
|
-
|
53
|
-
image = MiniMagick::Image.new("input.jpg")
|
54
|
-
image.resize "100x100"
|
55
|
-
|
56
|
-
Want to get some meta-information out?
|
57
|
-
|
58
|
-
image = MiniMagick::Image.from_file("input.jpg")
|
59
|
-
image[:width] # will get the width (you can also use :height and :format)
|
60
|
-
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
|
61
|
-
image["%m:%f %wx%h"] # Or you can use one of the many options of the format command found here http://www.imagemagick.org/script/command-line-options.php#format
|
62
|
-
|
63
|
-
|
64
|
-
== REQUIREMENTS:
|
65
|
-
|
66
|
-
You must have ImageMagick installed.
|
67
|
-
|
68
|
-
== INSTALL:
|
69
|
-
|
70
|
-
If you downloaded the plugin version, just drop the plugin into RAILS_ROOT/plugins/
|
71
|
-
|
72
|
-
If you installed this as a gem, then to get it to work add <require "mini_magick"> to RAILS_ROOT/config/environment.rb
|
73
|
-
|
74
|
-
If you have just downloaded this files then copy the mini_magick.rb file into your RAILS_ROOT/lib directory and add <require "mini-magick"> to RAILS_ROOT/config/environment.rb
|
75
|
-
|
76
|
-
MiniMagick does NOT require rails though. All the code you need to use MiniMagick is located in the mini_magick/lib/mini_magick.rb file.
|
77
|
-
|
78
|
-
== LICENSE:
|
79
|
-
|
80
|
-
(The MIT License)
|
81
|
-
|
82
|
-
Copyright (c) 2007 FIX
|
83
|
-
|
84
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
85
|
-
a copy of this software and associated documentation files (the
|
86
|
-
'Software'), to deal in the Software without restriction, including
|
87
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
88
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
89
|
-
permit persons to whom the Software is furnished to do so, subject to
|
90
|
-
the following conditions:
|
91
|
-
|
92
|
-
The above copyright notice and this permission notice shall be
|
93
|
-
included in all copies or substantial portions of the Software.
|
94
|
-
|
95
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
96
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
97
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
98
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
99
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
100
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
101
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/init.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require File.join(File.dirname(__FILE__), '../lib/image_temp_file')
|
3
|
-
|
4
|
-
class ImageTest < Test::Unit::TestCase
|
5
|
-
include MiniMagick
|
6
|
-
|
7
|
-
def test_image_temp_file
|
8
|
-
tmp = ImageTempFile.new('test')
|
9
|
-
assert_match %r{^test}, File::basename(tmp.path)
|
10
|
-
tmp = ImageTempFile.new('test.jpg')
|
11
|
-
assert_match %r{^test}, File::basename(tmp.path)
|
12
|
-
assert_match %r{\.jpg$}, File::basename(tmp.path)
|
13
|
-
end
|
14
|
-
end
|