mojo_magick 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +2 -0
- data/Rakefile +17 -0
- data/lib/mojo_magick.rb +6 -6
- data/lib/mojo_magick/version.rb +1 -1
- data/test/mojo_magick_test.rb +61 -33
- metadata +39 -54
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create use ruby-1.9.2-p318@mojo_magick
|
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
task 'default' => :test
|
4
|
+
|
5
|
+
desc "Default: run tests"
|
6
|
+
task :test do
|
7
|
+
require 'rake/runtest'
|
8
|
+
files = Dir.glob(File.join(File.dirname(__FILE__), 'test/*_test.rb'))
|
9
|
+
files.each do |f|
|
10
|
+
Rake.run_tests f
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
task :build do
|
15
|
+
`rm mojo_magick-*.gem`
|
16
|
+
puts `gem build mojo_magick.gemspec`
|
17
|
+
end
|
data/lib/mojo_magick.rb
CHANGED
@@ -101,11 +101,11 @@ module MojoMagick
|
|
101
101
|
def MojoMagick::resize(source_file, dest_file, options)
|
102
102
|
retval = nil
|
103
103
|
scale_options = []
|
104
|
-
scale_options <<
|
105
|
-
scale_options <<
|
106
|
-
scale_options <<
|
107
|
-
scale_options <<
|
108
|
-
scale_options = scale_options.join
|
104
|
+
scale_options << ">" unless options[:shrink_only].nil?
|
105
|
+
scale_options << "<" unless options[:expand_only].nil?
|
106
|
+
scale_options << "!" unless options[:absolute_aspect].nil?
|
107
|
+
scale_options << "^" unless options[:fill].nil?
|
108
|
+
scale_options = scale_options.join
|
109
109
|
|
110
110
|
extras = []
|
111
111
|
if !options[:width].nil? && !options[:height].nil?
|
@@ -119,7 +119,7 @@ module MojoMagick
|
|
119
119
|
extras << "-gravity Center"
|
120
120
|
extras << "-extent #{geometry}"
|
121
121
|
end
|
122
|
-
retval = raw_command("convert", "\"#{source_file}\" -resize #{geometry}#{scale_options} #{extras.join(' ')} \"#{dest_file}\"")
|
122
|
+
retval = raw_command("convert", "\"#{source_file}\" -resize \"#{geometry}#{scale_options}\" #{extras.join(' ')} \"#{dest_file}\"")
|
123
123
|
dest_file
|
124
124
|
end
|
125
125
|
|
data/lib/mojo_magick/version.rb
CHANGED
data/test/mojo_magick_test.rb
CHANGED
@@ -18,66 +18,96 @@ class MojoMagickTest < Test::Unit::TestCase
|
|
18
18
|
Dir::glob(File::join(@fixtures_path, '*')).each do |file|
|
19
19
|
FileUtils::cp(file, @working_path) if File::file?(file)
|
20
20
|
end
|
21
|
+
@test_image = File::join(@working_path, '5742.jpg')
|
22
|
+
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
25
|
+
def test_get_image_size
|
24
26
|
reset_images
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
assert_equal orig_image_size, File::size(test_image)
|
27
|
+
orig_image_size = File::size(@test_image)
|
28
|
+
retval = MojoMagick::get_image_size(@test_image)
|
29
|
+
assert_equal orig_image_size, File::size(@test_image)
|
29
30
|
assert_equal 500, retval[:height]
|
30
31
|
assert_equal 333, retval[:width]
|
32
|
+
end
|
31
33
|
|
34
|
+
def test_image_resize
|
32
35
|
# test basic resizing
|
36
|
+
reset_images
|
37
|
+
orig_image_size = File::size(@test_image)
|
33
38
|
size_test_temp = Tempfile::new('mojo_test')
|
34
39
|
size_test = size_test_temp.path
|
35
|
-
retval = MojoMagick::resize(test_image, size_test, {:width=>100, :height=>100})
|
40
|
+
retval = MojoMagick::resize(@test_image, size_test, {:width=>100, :height=>100})
|
36
41
|
assert_equal size_test, retval
|
37
|
-
assert_equal orig_image_size, File::size(test_image)
|
42
|
+
assert_equal orig_image_size, File::size(@test_image)
|
38
43
|
assert_equal retval, size_test
|
39
44
|
new_dimensions = MojoMagick::get_image_size(size_test)
|
40
45
|
assert_equal 100, new_dimensions[:height]
|
41
46
|
assert_equal 67, new_dimensions[:width]
|
42
47
|
|
43
48
|
# we should be able to resize image right over itself
|
44
|
-
retval = MojoMagick::resize(test_image, test_image, {:width=>100, :height=>100})
|
45
|
-
assert_equal test_image, retval
|
46
|
-
assert_not_equal orig_image_size, File::size(test_image)
|
47
|
-
new_dimensions = MojoMagick::get_image_size(test_image)
|
49
|
+
retval = MojoMagick::resize(@test_image, @test_image, {:width=>100, :height=>100})
|
50
|
+
assert_equal @test_image, retval
|
51
|
+
assert_not_equal orig_image_size, File::size(@test_image)
|
52
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
48
53
|
assert_equal 100, new_dimensions[:height]
|
49
54
|
assert_equal 67, new_dimensions[:width]
|
55
|
+
end
|
50
56
|
|
57
|
+
def test_shrink_with_big_dimensions
|
51
58
|
# image shouldn't resize if we specify very large dimensions and specify "shrink_only"
|
52
59
|
reset_images
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
60
|
+
size_test_temp = Tempfile::new('mojo_test')
|
61
|
+
size_test = size_test_temp.path
|
62
|
+
retval = MojoMagick::shrink(@test_image, size_test, {:width=>1000, :height=>1000})
|
63
|
+
assert_equal size_test, retval
|
64
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
57
65
|
assert_equal 500, new_dimensions[:height]
|
58
66
|
assert_equal 333, new_dimensions[:width]
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_shrink
|
70
|
+
reset_images
|
59
71
|
# image should resize if we specify small dimensions and shrink_only
|
60
|
-
retval = MojoMagick::shrink(test_image, test_image, {:width=>1000, :height=>100})
|
61
|
-
assert_equal test_image, retval
|
62
|
-
new_dimensions = MojoMagick::get_image_size(test_image)
|
72
|
+
retval = MojoMagick::shrink(@test_image, @test_image, {:width=>1000, :height=>100})
|
73
|
+
assert_equal @test_image, retval
|
74
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
63
75
|
assert_equal 100, new_dimensions[:height]
|
64
76
|
assert_equal 67, new_dimensions[:width]
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_resize_with_shrink_only_options
|
80
|
+
reset_images
|
81
|
+
# image should resize if we specify small dimensions and shrink_only
|
82
|
+
retval = MojoMagick::resize(@test_image, @test_image, {:shrink_only => true, :width=>400, :height=>400})
|
83
|
+
assert_equal @test_image, retval
|
84
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
85
|
+
assert_equal 400, new_dimensions[:height]
|
86
|
+
assert_equal 266, new_dimensions[:width]
|
87
|
+
end
|
65
88
|
|
89
|
+
def test_expand_with_small_dim
|
66
90
|
# image shouldn't resize if we specify small dimensions and expand_only
|
67
91
|
reset_images
|
68
|
-
orig_image_size = File::size(test_image)
|
69
|
-
retval = MojoMagick::expand(test_image, test_image, {:width=>10, :height=>10})
|
70
|
-
assert_equal test_image, retval
|
71
|
-
new_dimensions = MojoMagick::get_image_size(test_image)
|
92
|
+
orig_image_size = File::size(@test_image)
|
93
|
+
retval = MojoMagick::expand(@test_image, @test_image, {:width=>10, :height=>10})
|
94
|
+
assert_equal @test_image, retval
|
95
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
72
96
|
assert_equal 500, new_dimensions[:height]
|
73
97
|
assert_equal 333, new_dimensions[:width]
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_expand
|
101
|
+
reset_images
|
74
102
|
# image should resize if we specify large dimensions and expand_only
|
75
|
-
retval = MojoMagick::expand(test_image, test_image, {:width=>1000, :height=>1000})
|
76
|
-
assert_equal test_image, retval
|
77
|
-
new_dimensions = MojoMagick::get_image_size(test_image)
|
103
|
+
retval = MojoMagick::expand(@test_image, @test_image, {:width=>1000, :height=>1000})
|
104
|
+
assert_equal @test_image, retval
|
105
|
+
new_dimensions = MojoMagick::get_image_size(@test_image)
|
78
106
|
assert_equal 1000, new_dimensions[:height]
|
79
107
|
assert_equal 666, new_dimensions[:width]
|
108
|
+
end
|
80
109
|
|
110
|
+
def test_invalid_images
|
81
111
|
# test bad images
|
82
112
|
bad_image = File::join(@working_path, 'not_an_image.jpg')
|
83
113
|
zero_image = File::join(@working_path, 'zero_byte_image.jpg')
|
@@ -88,20 +118,18 @@ class MojoMagickTest < Test::Unit::TestCase
|
|
88
118
|
|
89
119
|
def test_resize_with_fill
|
90
120
|
reset_images
|
91
|
-
test_image = File::join(@working_path, '5742.jpg')
|
92
|
-
|
93
|
-
MojoMagick::
|
94
|
-
dim = MojoMagick::get_image_size(test_image)
|
121
|
+
@test_image = File::join(@working_path, '5742.jpg')
|
122
|
+
MojoMagick::resize(@test_image, @test_image, {:fill => true, :width => 100, :height => 100})
|
123
|
+
dim = MojoMagick::get_image_size(@test_image)
|
95
124
|
assert_equal 100, dim[:width]
|
96
125
|
assert_equal 150, dim[:height]
|
97
126
|
end
|
98
127
|
|
99
128
|
def test_resize_with_fill_and_crop
|
100
129
|
reset_images
|
101
|
-
test_image = File::join(@working_path, '5742.jpg')
|
102
|
-
|
103
|
-
MojoMagick::
|
104
|
-
dim = MojoMagick::get_image_size(test_image)
|
130
|
+
@test_image = File::join(@working_path, '5742.jpg')
|
131
|
+
MojoMagick::resize(@test_image, @test_image, {:fill => true, :crop => true, :width => 150, :height => 120})
|
132
|
+
dim = MojoMagick::get_image_size(@test_image)
|
105
133
|
assert_equal 150, dim[:width]
|
106
134
|
assert_equal 120, dim[:height]
|
107
135
|
end
|
metadata
CHANGED
@@ -1,52 +1,47 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mojo_magick
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 4
|
9
|
-
- 2
|
10
|
-
version: 0.4.2
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.3
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Steve Midgley
|
14
9
|
- Elliot Nelson
|
15
10
|
- Jon Rogers
|
16
11
|
autorequire:
|
17
12
|
bindir: bin
|
18
13
|
cert_chain: []
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
dependencies:
|
23
|
-
- !ruby/object:Gem::Dependency
|
14
|
+
date: 2012-09-08 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
24
17
|
name: rake
|
25
|
-
|
26
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
27
19
|
none: false
|
28
|
-
requirements:
|
29
|
-
- -
|
30
|
-
- !ruby/object:Gem::Version
|
31
|
-
|
32
|
-
segments:
|
33
|
-
- 0
|
34
|
-
version: "0"
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
35
24
|
type: :development
|
36
|
-
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
37
32
|
description: Simple Ruby stateless module interface to imagemagick.
|
38
|
-
email:
|
33
|
+
email:
|
39
34
|
- public@misuse.org
|
40
35
|
- j@2rye.com
|
41
36
|
executables: []
|
42
|
-
|
43
37
|
extensions: []
|
44
|
-
|
45
38
|
extra_rdoc_files: []
|
46
|
-
|
47
|
-
files:
|
39
|
+
files:
|
48
40
|
- .gitignore
|
41
|
+
- .rvmrc
|
42
|
+
- Gemfile
|
49
43
|
- README.md
|
44
|
+
- Rakefile
|
50
45
|
- init.rb
|
51
46
|
- lib/image_resources.rb
|
52
47
|
- lib/mojo_magick.rb
|
@@ -56,41 +51,31 @@ files:
|
|
56
51
|
- test/fixtures/not_an_image.jpg
|
57
52
|
- test/fixtures/zero_byte_image.jpg
|
58
53
|
- test/mojo_magick_test.rb
|
59
|
-
has_rdoc: true
|
60
54
|
homepage: http://github.com/bunnymatic/mojo_magick
|
61
55
|
licenses: []
|
62
|
-
|
63
56
|
post_install_message:
|
64
57
|
rdoc_options: []
|
65
|
-
|
66
|
-
require_paths:
|
58
|
+
require_paths:
|
67
59
|
- lib
|
68
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
61
|
none: false
|
70
|
-
requirements:
|
71
|
-
- -
|
72
|
-
- !ruby/object:Gem::Version
|
73
|
-
|
74
|
-
|
75
|
-
- 0
|
76
|
-
version: "0"
|
77
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
67
|
none: false
|
79
|
-
requirements:
|
80
|
-
- -
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
|
83
|
-
segments:
|
84
|
-
- 0
|
85
|
-
version: "0"
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
86
72
|
requirements: []
|
87
|
-
|
88
73
|
rubyforge_project: mojo_magick
|
89
|
-
rubygems_version: 1.
|
74
|
+
rubygems_version: 1.8.24
|
90
75
|
signing_key:
|
91
76
|
specification_version: 3
|
92
|
-
summary: mojo_magick-0.4.
|
93
|
-
test_files:
|
77
|
+
summary: mojo_magick-0.4.3
|
78
|
+
test_files:
|
94
79
|
- test/fixtures/5742.jpg
|
95
80
|
- test/fixtures/not_an_image.jpg
|
96
81
|
- test/fixtures/zero_byte_image.jpg
|