Class: Sorcery
- Inherits:
-
Object
- Object
- Sorcery
- Defined in:
- lib/image_sorcery.rb
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.
-
#identify(args = {}) ⇒ Object
Runs ImageMagick’s ‘identify’.
-
#initialize(file) ⇒ Sorcery
constructor
A new instance of Sorcery.
-
#manipulate!(args = {}) ⇒ Object
Runs ImageMagick’s ‘mogrify’.
Constructor Details
#initialize(file) ⇒ Sorcery
Returns a new instance of Sorcery.
4 5 6 |
# File 'lib/image_sorcery.rb', line 4 def initialize(file) @file = file end |
Instance Method Details
#convert(output, args = {}) ⇒ Object
Runs ImageMagick’s ‘convert’. See www.imagemagick.org/script/convert.php
23 24 25 26 27 28 29 30 31 |
# File 'lib/image_sorcery.rb', line 23 def convert(output, args={}) tokens = ["convert"] tokens << convert_to_arguments(args) if args tokens << " '#{@file}#{"[#{args[:layer].to_s}]" if args[:layer]}'" 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.
47 48 49 50 51 |
# File 'lib/image_sorcery.rb', line 47 def dimensions dimensions = identify(layer: 0, format: "%wx%h").chomp.split("x") { x: dimensions[0], y: dimensions[1] } end |
#identify(args = {}) ⇒ Object
Runs ImageMagick’s ‘identify’. See www.imagemagick.org/script/identify.php
36 37 38 39 40 41 42 43 |
# File 'lib/image_sorcery.rb', line 36 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
11 12 13 14 15 16 17 18 |
# File 'lib/image_sorcery.rb', line 11 def manipulate!(args={}) tokens = ["mogrify"] tokens << convert_to_arguments(args) if args tokens << " '#{@file}#{"[#{args[:layer].to_s}]" if args[:layer]}'" tokens = convert_to_command(tokens) success = run(tokens)[1] success end |