imanip 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/License.txt +20 -0
- data/Manifest.txt +19 -0
- data/README.txt +116 -0
- data/Rakefile +4 -0
- data/config/hoe.rb +73 -0
- data/config/requirements.rb +15 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/imanip.rb +3 -0
- data/lib/imanip/errors.rb +5 -0
- data/lib/imanip/image.rb +19 -0
- data/lib/imanip/imanip_magick.rb +147 -0
- data/lib/imanip/version.rb +9 -0
- data/test/landscape_test.jpg +0 -0
- data/test/portrait_test.jpg +0 -0
- data/test/test_helper.rb +23 -0
- data/test/test_imanip_magick.rb +94 -0
- data/uninstall.rb +1 -0
- metadata +77 -0
data/History.txt
ADDED
data/License.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Aaron Quint, Quirkey NYC, LLC.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
History.txt
|
2
|
+
License.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.txt
|
5
|
+
Rakefile
|
6
|
+
config/hoe.rb
|
7
|
+
config/requirements.rb
|
8
|
+
init.rb
|
9
|
+
install.rb
|
10
|
+
lib/imanip.rb
|
11
|
+
lib/imanip/errors.rb
|
12
|
+
lib/imanip/image.rb
|
13
|
+
lib/imanip/imanip_magick.rb
|
14
|
+
lib/imanip/version.rb
|
15
|
+
test/landscape_test.jpg
|
16
|
+
test/portrait_test.jpg
|
17
|
+
test/test_helper.rb
|
18
|
+
test/test_imanip_magick.rb
|
19
|
+
uninstall.rb
|
data/README.txt
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
= imanip
|
2
|
+
|
3
|
+
http://quirkey.sourceforge.com/imanip/
|
4
|
+
http://github.com/quirkey/imanip/
|
5
|
+
|
6
|
+
== DESCRIPTION:
|
7
|
+
|
8
|
+
Super-quick image resizing using the ImageMagick command line tools
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
- Simple API
|
13
|
+
- 0% Overhead
|
14
|
+
- Uses the ImageMagick command line tools (convert, identify)
|
15
|
+
|
16
|
+
NOTE:
|
17
|
+
The API is going to be changing a lot as I try to lock down something really useful. As a quick git-er-done type doodad
|
18
|
+
it works really well, and I'm already using it on some very high volume production sites.
|
19
|
+
|
20
|
+
== SYNOPSIS:
|
21
|
+
|
22
|
+
|
23
|
+
First things, first, Tell me where you keep them:
|
24
|
+
|
25
|
+
|
26
|
+
# Rails: production|development|etc.rb
|
27
|
+
# or somewhere that gets loaded before you initialize
|
28
|
+
|
29
|
+
Imanip::Interface::Magick.execute_path = '/path/to/your/bins/' # eg /usr/local/bin/
|
30
|
+
|
31
|
+
|
32
|
+
With an image file at /dir/image.jpg
|
33
|
+
|
34
|
+
image = Imanip::Image.new('/dir/image.jpg')
|
35
|
+
|
36
|
+
This will run identify on the image and make sure its convert-able. If it cant read or interpret it it will raise an Imanip::NotAnImageError.
|
37
|
+
Once you have the image you can check some properties/attributes
|
38
|
+
|
39
|
+
image.width #=> 410 (Fixnum)
|
40
|
+
image.height #=> 100 (Fixnum)
|
41
|
+
image.format #=> JPEG (String)
|
42
|
+
|
43
|
+
There are also some helpers to do some rule based cropping.
|
44
|
+
|
45
|
+
image.portrait? #=> false
|
46
|
+
image.landscape? #=> true
|
47
|
+
image.orientation #=> :landscape
|
48
|
+
|
49
|
+
After that you can resize and whatever
|
50
|
+
|
51
|
+
image.resize('outputfile.jpg', :dimensions => [200,100])
|
52
|
+
|
53
|
+
I like crop_resize better. It crops AND resizes so you get an image of the exact pixel dimensions you desire.
|
54
|
+
|
55
|
+
image.crop_resize('/file/to/output.jpg', :width => 50, :height => 50) #=> output file is an exact 50x50 image
|
56
|
+
|
57
|
+
You might also want to catch errors, because they will inevitably happen. Possible Errors
|
58
|
+
Imanip::Error # the root, the root, the root is on fire
|
59
|
+
Imanip::NotAnImageError # Descends from above, thrown during Imanip#Image.new
|
60
|
+
Imanip::CouldNotConvertError # Also from above, thrown if theres an issue with #resize or #crop_resize (options, etc.)
|
61
|
+
|
62
|
+
More examples coming soon.
|
63
|
+
|
64
|
+
== REQUIREMENTS:
|
65
|
+
|
66
|
+
You need ImageMagick. Really any version will do, but I am developing with ImageMagick 6.3.3.
|
67
|
+
http://www.imagemagick.org/script/download.php
|
68
|
+
|
69
|
+
|
70
|
+
== INSTALL:
|
71
|
+
|
72
|
+
First, install ImageMagick:
|
73
|
+
http://www.imagemagick.org/script/download.php
|
74
|
+
|
75
|
+
Make sure you get the command line tools:
|
76
|
+
|
77
|
+
$ which 'convert'
|
78
|
+
|
79
|
+
Imanip works as a gem or a plugin for Rails.
|
80
|
+
|
81
|
+
As a gem:
|
82
|
+
|
83
|
+
$ sudo gem install imanip
|
84
|
+
|
85
|
+
In Rails/environment.rb
|
86
|
+
config.gem 'imanip'
|
87
|
+
|
88
|
+
Or you can get the latest from github:
|
89
|
+
$ sudo gem sources -a http://gems.github.com
|
90
|
+
$ sudo gem install quirkey-imanip
|
91
|
+
|
92
|
+
|
93
|
+
== LICENSE:
|
94
|
+
|
95
|
+
(The MIT License)
|
96
|
+
|
97
|
+
Copyright (c) 2008 Aaron Quint, Quirkey
|
98
|
+
|
99
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
100
|
+
a copy of this software and associated documentation files (the
|
101
|
+
'Software'), to deal in the Software without restriction, including
|
102
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
103
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
104
|
+
permit persons to whom the Software is furnished to do so, subject to
|
105
|
+
the following conditions:
|
106
|
+
|
107
|
+
The above copyright notice and this permission notice shall be
|
108
|
+
included in all copies or substantial portions of the Software.
|
109
|
+
|
110
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
111
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
112
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
113
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
114
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
115
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
116
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
data/config/hoe.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'imanip/version'
|
2
|
+
|
3
|
+
AUTHOR = 'Aaron Quint' # can also be an array of Authors
|
4
|
+
EMAIL = 'aaron@quirkey.com'
|
5
|
+
DESCRIPTION = "Super-quick image resizing using the ImageMagick command line tools"
|
6
|
+
GEM_NAME = 'imanip' # what ppl will type to install your gem
|
7
|
+
RUBYFORGE_PROJECT = 'quirkey' # The unix name for your project
|
8
|
+
HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
|
9
|
+
DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
|
10
|
+
EXTRA_DEPENDENCIES = [
|
11
|
+
# ['activesupport', '>= 1.3.1']
|
12
|
+
] # An array of rubygem dependencies [name, version]
|
13
|
+
|
14
|
+
@config_file = "~/.rubyforge/user-config.yml"
|
15
|
+
@config = nil
|
16
|
+
RUBYFORGE_USERNAME = "unknown"
|
17
|
+
def rubyforge_username
|
18
|
+
unless @config
|
19
|
+
begin
|
20
|
+
@config = YAML.load(File.read(File.expand_path(@config_file)))
|
21
|
+
rescue
|
22
|
+
puts <<-EOS
|
23
|
+
ERROR: No rubyforge config file found: #{@config_file}
|
24
|
+
Run 'rubyforge setup' to prepare your env for access to Rubyforge
|
25
|
+
- See http://newgem.rubyforge.org/rubyforge.html for more details
|
26
|
+
EOS
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
RUBYFORGE_USERNAME.replace @config["username"]
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
REV = nil
|
35
|
+
# UNCOMMENT IF REQUIRED:
|
36
|
+
# REV = YAML.load(`svn info`)['Revision']
|
37
|
+
VERS = Imanip::VERSION::STRING + (REV ? ".#{REV}" : "")
|
38
|
+
RDOC_OPTS = ['--quiet', '--title', 'imanip documentation',
|
39
|
+
"--opname", "index.html",
|
40
|
+
"--line-numbers",
|
41
|
+
"--main", "README",
|
42
|
+
"--inline-source"]
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
def extra_deps
|
46
|
+
@extra_deps.reject! { |x| Array(x).first == 'hoe' }
|
47
|
+
@extra_deps
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Generate all the Rake tasks
|
52
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
53
|
+
$hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
54
|
+
p.developer(AUTHOR, EMAIL)
|
55
|
+
p.description = DESCRIPTION
|
56
|
+
p.summary = DESCRIPTION
|
57
|
+
p.url = HOMEPATH
|
58
|
+
p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
|
59
|
+
p.test_globs = ["test/**/test_*.rb"]
|
60
|
+
p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
|
61
|
+
|
62
|
+
# == Optional
|
63
|
+
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
64
|
+
#p.extra_deps = EXTRA_DEPENDENCIES
|
65
|
+
|
66
|
+
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
67
|
+
end
|
68
|
+
|
69
|
+
CHANGES = $hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
|
70
|
+
PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
|
71
|
+
$hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
|
72
|
+
$hoe.rsync_args = '-av --delete --ignore-errors'
|
73
|
+
$hoe.spec.post_install_message = File.open(File.dirname(__FILE__) + "/../PostInstall.txt").read rescue ""
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
include FileUtils
|
3
|
+
|
4
|
+
require 'rubygems'
|
5
|
+
%w[rake hoe newgem rubigen].each do |req_gem|
|
6
|
+
begin
|
7
|
+
require req_gem
|
8
|
+
rescue LoadError
|
9
|
+
puts "This Rakefile requires the '#{req_gem}' RubyGem."
|
10
|
+
puts "Installation: gem install #{req_gem} -y"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
$:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
data/lib/imanip.rb
ADDED
data/lib/imanip/image.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Imanip
|
2
|
+
class Image
|
3
|
+
|
4
|
+
def initialize(path,interface = :magick)
|
5
|
+
@image_path = path
|
6
|
+
load_interface(interface)
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
def load_interface(interface)
|
11
|
+
@interface = Imanip::Interface.const_get("#{interface.to_s.capitalize}").new(@image_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method, *args)
|
15
|
+
@interface.send(method,*args)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
module Imanip
|
2
|
+
module Interface
|
3
|
+
|
4
|
+
class Magick
|
5
|
+
class << self
|
6
|
+
@execute_path = ''
|
7
|
+
attr_accessor :execute_path
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :width, :height, :format
|
11
|
+
|
12
|
+
def initialize(path)
|
13
|
+
@image_path = path
|
14
|
+
identify
|
15
|
+
end
|
16
|
+
|
17
|
+
def dimensions
|
18
|
+
[width,height]
|
19
|
+
end
|
20
|
+
|
21
|
+
def portrait?
|
22
|
+
width < height
|
23
|
+
end
|
24
|
+
|
25
|
+
def landscape?
|
26
|
+
width > height
|
27
|
+
end
|
28
|
+
|
29
|
+
def orientation
|
30
|
+
landscape? ? :landscape : :portrait
|
31
|
+
end
|
32
|
+
|
33
|
+
def crop(to_file, options = {})
|
34
|
+
@options = options
|
35
|
+
parse_size_options!
|
36
|
+
@options[:crop] = to_geometry_string(@geometry)
|
37
|
+
convert(to_file, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def resize(to_file, options = {})
|
41
|
+
@options = options
|
42
|
+
parse_size_options!
|
43
|
+
@options[:resize] = to_geometry_string(@geometry)
|
44
|
+
convert(to_file, @options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def crop_resize(to_file, options = {})
|
48
|
+
@options = options.dup
|
49
|
+
parse_size_options!
|
50
|
+
crop_resize_string = ""
|
51
|
+
crop_width = @geometry[:width]
|
52
|
+
crop_height = @geometry[:height]
|
53
|
+
if !(crop_height.nil? || crop_width.nil?)
|
54
|
+
if width == height
|
55
|
+
if portrait?
|
56
|
+
crop_resize_string << "-resize #{to_geometry_string(:width => crop_width)}"
|
57
|
+
else
|
58
|
+
crop_resize_string << "-resize #{to_geometry_string(:height => crop_height)}"
|
59
|
+
end
|
60
|
+
elsif portrait?
|
61
|
+
crop_resize_string << "-resize #{to_geometry_string(:width => crop_width)}"
|
62
|
+
else
|
63
|
+
crop_resize_string << "-resize #{to_geometry_string(:height => crop_height)}"
|
64
|
+
end
|
65
|
+
else
|
66
|
+
crop_resize_string << "-resize #{to_geometry_string(:height => crop_height, :width => crop_width)}"
|
67
|
+
end
|
68
|
+
gravity = @options.delete(:gravity) || 'North'
|
69
|
+
crop_resize_string << " -gravity '#{gravity}'"
|
70
|
+
crop_resize_string << " -crop #{to_geometry_string(@geometry)}+0+0"
|
71
|
+
crop_resize_string << " #{options_to_string(@options)}"
|
72
|
+
convert(to_file,crop_resize_string)
|
73
|
+
end
|
74
|
+
alias :crop_resized :crop_resize
|
75
|
+
|
76
|
+
def identify(options = {})
|
77
|
+
response = execute("#{execute_path}identify #{options_to_string(options)} #{@image_path}")
|
78
|
+
matches = response.match(/(JPEG|PNG|GIF)\ (\d+)x(\d+)/)
|
79
|
+
raise NotAnImageError, "Could not identify the image #{@image_path} as an image: #{response}" if matches.nil?
|
80
|
+
@format = matches[1]
|
81
|
+
@width = matches[2].to_i
|
82
|
+
@height = matches[3].to_i
|
83
|
+
end
|
84
|
+
|
85
|
+
def convert(to_file,options = {})
|
86
|
+
command = "#{execute_path}convert #{@image_path} #{options_to_string(options)} #{to_file}"
|
87
|
+
# puts command
|
88
|
+
response = execute(command)
|
89
|
+
# catch errors in response
|
90
|
+
possible_errors = [
|
91
|
+
/invalid argument/
|
92
|
+
]
|
93
|
+
possible_errors.each do |error|
|
94
|
+
raise(CouldNotConvertError, response + " when " + command) if response =~ error
|
95
|
+
end
|
96
|
+
# assert that the new file exits
|
97
|
+
File.readable?(to_file) ? to_file : raise(CouldNotConvertError)
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
|
102
|
+
def parse_size_options!
|
103
|
+
@geometry = {}
|
104
|
+
if @options[:geometry]
|
105
|
+
width, height = @options.delete(:geometry).split('x')
|
106
|
+
@geometry = {:width => width, :height => height}
|
107
|
+
end
|
108
|
+
if @options[:dimensions]
|
109
|
+
width, height = @options.delete(:dimensions)
|
110
|
+
@geometry = {:width => width, :height => height}
|
111
|
+
end
|
112
|
+
@geometry = {:width => @options.delete(:width), :height => @options.delete(:height) } if @options[:width] || @options[:height]
|
113
|
+
@geometry.collect {|d| d[1].to_i unless d.nil? }
|
114
|
+
end
|
115
|
+
|
116
|
+
def to_geometry_string(width_height)
|
117
|
+
# puts "width_height: #{width_height.inspect}"
|
118
|
+
case width_height
|
119
|
+
when Array
|
120
|
+
width_height.join("x")
|
121
|
+
when Hash
|
122
|
+
"#{width_height[:width]}x#{width_height[:height]}"
|
123
|
+
else
|
124
|
+
width_height.to_s
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
def options_to_string(options)
|
129
|
+
return options if options.is_a?(String)
|
130
|
+
option_string = ""
|
131
|
+
options.each do |name,value|
|
132
|
+
option_string << "-#{name} #{value} "
|
133
|
+
end
|
134
|
+
option_string
|
135
|
+
end
|
136
|
+
|
137
|
+
def execute(command)
|
138
|
+
`#{command} 2>&1`
|
139
|
+
end
|
140
|
+
|
141
|
+
def execute_path
|
142
|
+
self.class.execute_path
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
Binary file
|
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/imanip'))
|
3
|
+
|
4
|
+
class Test::Unit::TestCase
|
5
|
+
|
6
|
+
protected
|
7
|
+
def current_path
|
8
|
+
File.expand_path(File.dirname(__FILE__))
|
9
|
+
end
|
10
|
+
|
11
|
+
def portrait_image_path
|
12
|
+
File.join(current_path,'portrait_test.jpg')
|
13
|
+
end
|
14
|
+
|
15
|
+
def landscape_image_path
|
16
|
+
File.join(current_path,'landscape_test.jpg')
|
17
|
+
end
|
18
|
+
|
19
|
+
def new_image_path
|
20
|
+
File.join(current_path, "new_file.jpg")
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
# require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
2
|
+
|
3
|
+
class ImanipMagickTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@portrait_image = new_imanip_image(portrait_image_path)
|
7
|
+
@landscape_image = new_imanip_image(landscape_image_path)
|
8
|
+
end
|
9
|
+
|
10
|
+
def teardown
|
11
|
+
File.unlink(new_image_path) if File.readable?(new_image_path)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_should_raise_error_if_not_an_image
|
15
|
+
assert_raise(Imanip::NotAnImageError) do
|
16
|
+
new_imanip_image(__FILE__)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_should_return_dimensions_as_array
|
21
|
+
dimensions = @portrait_image.dimensions
|
22
|
+
assert dimensions.is_a?(Array)
|
23
|
+
assert_equal [411,519], dimensions
|
24
|
+
|
25
|
+
dimensions = @landscape_image.dimensions
|
26
|
+
assert dimensions.is_a?(Array)
|
27
|
+
assert_equal [400,315], dimensions
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_portrait_should_return_true_for_portrait_image
|
31
|
+
assert @portrait_image.portrait?
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_portrait_should_return_false_for_landscape_image
|
35
|
+
assert !@landscape_image.portrait?
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_landscape_should_return_true_for_landscape_image
|
39
|
+
assert @landscape_image.landscape?
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_landscape_should_return_false_for_portrait_image
|
43
|
+
assert !@portrait_image.landscape?
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_resize_should_save_to_new_file
|
47
|
+
assert !File.readable?(new_image_path)
|
48
|
+
assert @portrait_image.resize(new_image_path, :width => 50)
|
49
|
+
assert File.readable?(new_image_path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_resize_should_resize_image_to_new_image_at_dimensions
|
53
|
+
dimensions = [100,126]
|
54
|
+
assert @portrait_image.resize(new_image_path, :dimensions => dimensions)
|
55
|
+
@new_image = new_imanip_image(new_image_path)
|
56
|
+
assert_equal dimensions, @new_image.dimensions
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_resize_should_resize_image_to_new_image_at_width
|
60
|
+
width = 100
|
61
|
+
assert @portrait_image.resize(new_image_path, :width => width)
|
62
|
+
@new_image = new_imanip_image(new_image_path)
|
63
|
+
assert_equal width, @new_image.width
|
64
|
+
assert_not_equal @portrait_image.height, @new_image.height
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_crop_resize_should_crop_and_resize_image_to_exact_dimensions
|
68
|
+
dimensions = [200,153]
|
69
|
+
assert @portrait_image.crop_resize(new_image_path, :dimensions => dimensions)
|
70
|
+
@new_image = new_imanip_image(new_image_path)
|
71
|
+
assert_equal dimensions, @new_image.dimensions
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_crop_resize_should_crop_and_resize_image_to_exact_dimensions_with_square_dimensions
|
75
|
+
dimensions = [100,100]
|
76
|
+
assert @landscape_image.crop_resize(new_image_path, :dimensions => dimensions)
|
77
|
+
@new_image = new_imanip_image(new_image_path)
|
78
|
+
assert_equal dimensions, @new_image.dimensions
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
def test_should_throw_errors_if_image_could_not_be_converted
|
83
|
+
assert_raise(Imanip::CouldNotConvertError) do
|
84
|
+
@portrait_image.resize(new_image_path, :v => "bad option")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
protected
|
89
|
+
def new_imanip_image(path,interface = :magick)
|
90
|
+
Imanip::Image.new(path,interface)
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imanip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Quint
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-13 00:00:00 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Super-quick image resizing using the ImageMagick command line tools
|
17
|
+
email:
|
18
|
+
- aaron@quirkey.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- History.txt
|
25
|
+
- License.txt
|
26
|
+
- Manifest.txt
|
27
|
+
- README.txt
|
28
|
+
files:
|
29
|
+
- History.txt
|
30
|
+
- License.txt
|
31
|
+
- Manifest.txt
|
32
|
+
- README.txt
|
33
|
+
- Rakefile
|
34
|
+
- config/hoe.rb
|
35
|
+
- config/requirements.rb
|
36
|
+
- init.rb
|
37
|
+
- install.rb
|
38
|
+
- lib/imanip.rb
|
39
|
+
- lib/imanip/errors.rb
|
40
|
+
- lib/imanip/image.rb
|
41
|
+
- lib/imanip/imanip_magick.rb
|
42
|
+
- lib/imanip/version.rb
|
43
|
+
- test/landscape_test.jpg
|
44
|
+
- test/portrait_test.jpg
|
45
|
+
- test/test_helper.rb
|
46
|
+
- test/test_imanip_magick.rb
|
47
|
+
- uninstall.rb
|
48
|
+
has_rdoc: true
|
49
|
+
homepage: http://quirkey.rubyforge.org
|
50
|
+
post_install_message: ""
|
51
|
+
rdoc_options:
|
52
|
+
- --main
|
53
|
+
- README.txt
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: quirkey
|
71
|
+
rubygems_version: 1.1.1
|
72
|
+
signing_key:
|
73
|
+
specification_version: 2
|
74
|
+
summary: Super-quick image resizing using the ImageMagick command line tools
|
75
|
+
test_files:
|
76
|
+
- test/test_helper.rb
|
77
|
+
- test/test_imanip_magick.rb
|