lib/mojo_magick.rb in mojo_magick-0.3.0 vs lib/mojo_magick.rb in mojo_magick-0.4.0
- old
+ new
@@ -50,12 +50,10 @@
# bang (!) can be appended to command names to use the '+' versions
# instead of '-' versions.
#
module MojoMagick
- VERSION = "0.2.0"
-
class MojoMagickException < StandardError; end
class MojoError < MojoMagickException; end
class MojoFailed < MojoMagickException; end
# enable resource limiting functionality
@@ -116,12 +114,12 @@
geometry = "#{options[:percent]}%"
else
raise MojoMagickError, "Unknown options for method resize: #{options.inspect}"
end
if !options[:fill].nil? && !options[:crop].nil?
+ extras << "-gravity Center"
extras << "-extent #{geometry}"
- extras << "-gravity center"
end
retval = raw_command("convert", "\"#{source_file}\" -resize #{geometry}#{scale_options} #{extras.join(' ')} \"#{dest_file}\"")
dest_file
end
@@ -152,10 +150,27 @@
yield opts
opts.file dest if dest
raw_command('mogrify', opts.to_s)
end
+
+ def MojoMagick::tempfile(*opts)
+ begin
+ data = opts[0]
+ rest = opts[1]
+ ext = rest && rest[:format]
+ file = Tempfile.new(["mojo", ext ? '.' + ext.to_s : ''])
+ file.binmode
+ file.write(data)
+ file.path
+ rescue Exception => ex
+ raise
+ end
+ ensure
+ file.close
+ end
+
# Option builder used in #convert and #mogrify helpers.
class OptBuilder
def initialize
@opts = []
end
@@ -178,12 +193,17 @@
self
end
alias files file
# Create a temporary file for the given image and add to command line
- def blob(arg)
- file MojoMagick::tempfile(arg)
+ def blob(*args)
+ data = args[0]
+ opts = args[1] || {}
+ [:format, :depth, :size].each do |opt|
+ self.send(opt, opts[opt].to_s) if opts[opt]
+ end
+ file MojoMagick::tempfile(data, opts)
end
# Generic commands. Arguments will be formatted if necessary
def method_missing(command, *args)
if command.to_s[-1, 1] == '!'
@@ -208,18 +228,9 @@
@opts << "\"#{arg.gsub('"', '\"')}\""
else
@opts << arg
end
end
- end
-
- def MojoMagick::tempfile(data)
- file = Tempfile.new("mojo")
- file.binmode
- file.write(data)
- file.path
- ensure
- file.close
end
end # MojoMagick