lib/mini_magick.rb in mini_magick-3.1 vs lib/mini_magick.rb in mini_magick-3.2
- old
+ new
@@ -154,10 +154,11 @@
#
# @example
# image["format"] #=> "TIFF"
# image["height"] #=> 41 (pixels)
# image["width"] #=> 50 (pixels)
+ # image["colorspace"] #=> "DirectClassRGB"
# image["dimensions"] #=> [50, 41]
# image["size"] #=> 2050 (bits)
# image["original_at"] #=> 2005-02-23 23:17:24 +0000 (Read from Exif data)
# image["EXIF:ExifVersion"] #=> "0220" (Can read anything from Exif)
#
@@ -165,10 +166,12 @@
# @see For reference see http://www.imagemagick.org/script/command-line-options.php#format
# @return [String, Numeric, Array, Time, Object] Depends on the method called! Defaults to String for unknown commands
def [](value)
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
case value.to_s
+ when "colorspace"
+ run_command("identify", "-format", format_option("%r"), escaped_path).split("\n")[0]
when "format"
run_command("identify", "-format", format_option("%m"), escaped_path).split("\n")[0]
when "height"
run_command("identify", "-format", format_option("%h"), escaped_path).split("\n")[0].to_i
when "width"
@@ -214,11 +217,14 @@
#
# @param format [String] The target format... like 'jpg', 'gif', 'tiff', etc.
# @param page [Integer] If this is an animated gif, say which 'page' you want with an integer. Leave as default if you don't care.
# @return [nil]
def format(format, page = 0)
- run_command("mogrify", "-format", format, @path)
+ c = CommandBuilder.new('mogrify', '-format', format)
+ yield c if block_given?
+ c << @path
+ run(c)
old_path = @path.dup
@path.sub!(/(\.\w*)?$/, ".#{format}")
File.delete(old_path) if old_path != @path
@@ -248,11 +254,13 @@
# @return [IOStream, Boolean] If you pass in a file location [String] then you get a success boolean. If its a stream, you get it back.
# Writes the temporary image that we are using for processing to the output path
def write(output_to)
if output_to.kind_of?(String) || !output_to.respond_to?(:write)
FileUtils.copy_file @path, output_to
- run_command "identify", output_to # Verify that we have a good image
+ # We need to escape the output path if it contains a space
+ escaped_output_to = output_to.to_s.gsub(' ', '\\ ')
+ run_command "identify", escaped_output_to # Verify that we have a good image
else # stream
File.open(@path, "rb") do |f|
f.binmode
while chunk = f.read(8192)
output_to.write(chunk)
@@ -324,10 +332,15 @@
def format_option(format)
windows? ? "\"#{format}\\n\"" : "\"#{format}\\\\n\""
end
def run_command(command, *args)
+ # -ping "efficiently determine image characteristics."
+ if command == 'identify'
+ args.unshift '-ping'
+ end
+
run(CommandBuilder.new(command, *args))
end
def run(command_builder)
command = command_builder.command
@@ -387,29 +400,35 @@
guessed_command_name = symbol.to_s.gsub('_','-')
if guessed_command_name == "format"
raise Error, "You must call 'format' on the image object directly!"
elsif MOGRIFY_COMMANDS.include?(guessed_command_name)
add(guessed_command_name, *options)
+ self
else
super(symbol, *args)
end
end
+ def +(*options)
+ push(@args.pop.gsub /^-/, '+')
+ if options.any?
+ options.each do |o|
+ push "\"#{ o }\""
+ end
+ end
+ end
+
def add(command, *options)
push "-#{command}"
if options.any?
- push "\"#{options.join(" ")}\""
+ options.each do |o|
+ push "\"#{ o }\""
+ end
end
end
def push(arg)
@args << arg.to_s.strip
end
alias :<< :push
-
- # @deprecated Please don't use the + method its has been deprecated
- def +(value)
- warn "Warning: The MiniMagick::ComandBuilder#+ command has been deprecated. Please use c << '+#{value}' instead"
- push "+#{value}"
- end
end
end