mini_magick 1.1.0 → 1.2.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/Rakefile +2 -2
- data/lib/mini_magick.rb +33 -13
- data/test/mini_magick_test.rb +10 -1
- metadata +3 -3
data/Rakefile
CHANGED
@@ -49,7 +49,7 @@ spec = Gem::Specification.new do |s|
|
|
49
49
|
s.author = "Corey Johnson"
|
50
50
|
s.email = "probablycorey@gmail.com"
|
51
51
|
s.rubyforge_project = PKG_NAME
|
52
|
-
s.homepage = "http://
|
52
|
+
s.homepage = "http://gleepglop.com"
|
53
53
|
|
54
54
|
s.has_rdoc = true
|
55
55
|
s.requirements << 'none'
|
@@ -63,6 +63,6 @@ end
|
|
63
63
|
|
64
64
|
Rake::GemPackageTask.new(spec) do |p|
|
65
65
|
p.gem_spec = spec
|
66
|
-
p.need_tar =
|
66
|
+
p.need_tar = false
|
67
67
|
p.need_zip = true
|
68
68
|
end
|
data/lib/mini_magick.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
require "open-uri"
|
2
2
|
require "tempfile"
|
3
3
|
require "stringio"
|
4
|
+
require "fileutils"
|
4
5
|
|
5
6
|
module MiniMagick
|
6
7
|
class MiniMagickError < Exception; end
|
7
8
|
|
8
|
-
VERSION = '1.
|
9
|
+
VERSION = '1.2.0'
|
9
10
|
|
10
11
|
class Image
|
11
12
|
attr :path
|
@@ -17,11 +18,10 @@ module MiniMagick
|
|
17
18
|
begin
|
18
19
|
tmp = Tempfile.new("minimagic")
|
19
20
|
tmp.binmode
|
20
|
-
tmp.write(blob)
|
21
|
+
tmp.write(blob)
|
21
22
|
ensure
|
22
23
|
tmp.close
|
23
24
|
end
|
24
|
-
|
25
25
|
return self.new(tmp.path)
|
26
26
|
end
|
27
27
|
|
@@ -46,11 +46,11 @@ module MiniMagick
|
|
46
46
|
# Why do I go to the trouble of putting in newline chars? Because otherwise animated gifs screw everything up
|
47
47
|
case value.to_s
|
48
48
|
when "format"
|
49
|
-
run_command("identify", "-format", "%m
|
49
|
+
run_command("identify", "-format", format_option("%m"), @path).split("\n")[0]
|
50
50
|
when "height"
|
51
|
-
run_command("identify", "-format", "%h
|
51
|
+
run_command("identify", "-format", format_option("%h"), @path).split("\n")[0].to_i
|
52
52
|
when "width"
|
53
|
-
run_command("identify", "-format", "%w
|
53
|
+
run_command("identify", "-format", format_option("%w"), @path).split("\n")[0].to_i
|
54
54
|
when "original_at"
|
55
55
|
# Get the EXIF original capture as a Time object
|
56
56
|
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
|
@@ -68,13 +68,11 @@ module MiniMagick
|
|
68
68
|
|
69
69
|
raise "Unable to format to #{format}" unless File.exists?(@path)
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
|
+
# Writes the temporary image that we are using for processing to the output path
|
72
73
|
def write(output_path)
|
73
|
-
|
74
|
-
|
75
|
-
output_file.write(image_file.read)
|
76
|
-
end
|
77
|
-
end
|
74
|
+
FileUtils.copy_file @path, output_path
|
75
|
+
run_command "identify #{output_path}" # Verify that we have a good image
|
78
76
|
end
|
79
77
|
|
80
78
|
# If an unknown method is called then it is sent through the morgrify program
|
@@ -94,9 +92,31 @@ module MiniMagick
|
|
94
92
|
# Private (Don't look in here!)
|
95
93
|
# -----------------------------
|
96
94
|
private
|
95
|
+
|
96
|
+
# Check to see if we are running on win32 -- we need to escape things differently
|
97
|
+
def windows?
|
98
|
+
!(RUBY_PLATFORM =~ /win32/).nil?
|
99
|
+
end
|
100
|
+
|
101
|
+
# Outputs a carriage-return delimited format string for Unix and Windows
|
102
|
+
def format_option(format)
|
103
|
+
if windows?
|
104
|
+
format = "#{format}\\n"
|
105
|
+
else
|
106
|
+
format = "#{format}\\\\n"
|
107
|
+
end
|
108
|
+
end
|
97
109
|
|
98
110
|
def run_command(command, *args)
|
99
|
-
args = args.collect
|
111
|
+
args = args.collect do |a|
|
112
|
+
a = a.to_s
|
113
|
+
unless a[0,1] == '-' # don't quote switches
|
114
|
+
"\"#{a}\"" # values quoted because they can contain characters like '>'
|
115
|
+
else
|
116
|
+
a
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
100
120
|
output = `#{command} #{args.join(' ')}`
|
101
121
|
|
102
122
|
if $? != 0
|
data/test/mini_magick_test.rb
CHANGED
@@ -12,7 +12,7 @@ class ImageTest < Test::Unit::TestCase
|
|
12
12
|
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
|
13
13
|
|
14
14
|
def test_image_from_blob
|
15
|
-
File.open(SIMPLE_IMAGE_PATH, "
|
15
|
+
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
|
16
16
|
image = Image.from_blob(f.read)
|
17
17
|
end
|
18
18
|
end
|
@@ -64,6 +64,15 @@ class ImageTest < Test::Unit::TestCase
|
|
64
64
|
assert_match(/^gif$/i, image[:format])
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_image_resize_with_minimum
|
68
|
+
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
69
|
+
original_width, original_height = image[:width], image[:height]
|
70
|
+
image.resize "#{original_width + 10}x#{original_height + 10}>"
|
71
|
+
|
72
|
+
assert_equal original_width, image[:width]
|
73
|
+
assert_equal original_height, image[:height]
|
74
|
+
end
|
75
|
+
|
67
76
|
def test_image_combine_options_resize_blur
|
68
77
|
image = Image.from_file(SIMPLE_IMAGE_PATH)
|
69
78
|
image.combine_options do |c|
|
metadata
CHANGED
@@ -3,13 +3,13 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: mini_magick
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2006-
|
6
|
+
version: 1.2.0
|
7
|
+
date: 2006-08-07 00:00:00 -04:00
|
8
8
|
summary: Manipulate images with minimal use of memory.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: probablycorey@gmail.com
|
12
|
-
homepage: http://
|
12
|
+
homepage: http://gleepglop.com
|
13
13
|
rubyforge_project: mini_magick
|
14
14
|
description: Uses command-line ImageMagick tools to resize, rotate, and mogrify images.
|
15
15
|
autorequire: mini_magick
|