Class: ImageSorcery
- Inherits:
-
Object
- Object
- ImageSorcery
- Defined in:
- lib/gm_support.rb,
lib/image_sorcery.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
Instance Method Summary collapse
-
#convert(output, args = {}) ⇒ Object
Runs ImageMagick’s ‘convert’.
-
#dimensions ⇒ Object
Return the x and y dimensions of an image as a hash.
- #filename_changed? ⇒ Boolean
-
#height ⇒ Object
Returns the y dimension of an image as an integer.
-
#identify(args = {}) ⇒ Object
Runs ImageMagick’s ‘identify’.
-
#initialize(file) ⇒ ImageSorcery
constructor
A new instance of ImageSorcery.
-
#manipulate!(args = {}) ⇒ Object
Runs ImageMagick’s ‘mogrify’.
-
#montage(sources, args = {}) ⇒ Object
Runs ImageMagick’s ‘montage’.
-
#width ⇒ Object
Returns the x dimension of an image as an integer.
Constructor Details
#initialize(file) ⇒ ImageSorcery
Returns a new instance of ImageSorcery.
6 7 8 |
# File 'lib/image_sorcery.rb', line 6 def initialize(file) @file = file end |
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
4 5 6 |
# File 'lib/image_sorcery.rb', line 4 def file @file end |
Class Method Details
.gm(file) ⇒ Object
9 10 11 12 13 |
# File 'lib/gm_support.rb', line 9 def gm file instance = new(file) instance.extend GmSupport instance end |
Instance Method Details
#convert(output, args = {}) ⇒ Object
Runs ImageMagick’s ‘convert’. See www.imagemagick.org/script/convert.php
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/image_sorcery.rb', line 27 def convert(output, args={}) tokens = ["convert"] tokens << convert_to_arguments(args) if args tokens << " '#{@file}#{"[#{args[:layer].to_s}]" if args[:layer]}'" tokens << " -annotate #{args[:annotate].to_s}" if args[:annotate] tokens << " #{output}" tokens = convert_to_command(tokens) success = run(tokens)[1] success end |
#dimensions ⇒ Object
Return the x and y dimensions of an image as a hash.
52 53 54 55 56 |
# File 'lib/image_sorcery.rb', line 52 def dimensions dimensions = identify(:layer => 0, :format => "%wx%h").chomp.split("x") { :x => dimensions[0].to_i, :y => dimensions[1].to_i } end |
#filename_changed? ⇒ Boolean
82 83 84 |
# File 'lib/image_sorcery.rb', line 82 def filename_changed? (@filename_changed) end |
#height ⇒ Object
Returns the y dimension of an image as an integer
66 67 68 |
# File 'lib/image_sorcery.rb', line 66 def height dimensions()[:y] end |
#identify(args = {}) ⇒ Object
Runs ImageMagick’s ‘identify’. See www.imagemagick.org/script/identify.php
41 42 43 44 45 46 47 48 |
# File 'lib/image_sorcery.rb', line 41 def identify(args={}) tokens = ["identify"] tokens << convert_to_arguments(args) if args tokens << " '#{@file}#{"[#{args[:layer].to_s}]" if args[:layer]}'" tokens = convert_to_command(tokens) output = run(tokens)[0] output end |
#manipulate!(args = {}) ⇒ Object
Runs ImageMagick’s ‘mogrify’. See www.imagemagick.org/script/mogrify.php
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/image_sorcery.rb', line 13 def manipulate!(args={}) tokens = ["mogrify"] tokens << convert_to_arguments(args) if args tokens << " '#{@file}#{"[#{args[:layer].to_s}]" if args[:layer]}'" tokens << " -annotate #{args[:annotate].to_s}" if args[:annotate] tokens = convert_to_command(tokens) success = run(tokens)[1] replace_file(args[:format].to_s.downcase, args[:layer]) if success && args[:format] success end |
#montage(sources, args = {}) ⇒ Object
Runs ImageMagick’s ‘montage’. See www.imagemagick.org/script/montage.php
73 74 75 76 77 78 79 80 |
# File 'lib/image_sorcery.rb', line 73 def montage(sources, args={}) tokens = ["montage"] tokens << convert_to_arguments(args) if args sources.each {|source| tokens << " '#{source}'" } tokens << " '#{@file}'" tokens = convert_to_command(tokens) success = run(tokens)[1] end |
#width ⇒ Object
Returns the x dimension of an image as an integer
60 61 62 |
# File 'lib/image_sorcery.rb', line 60 def width dimensions()[:x] end |