lib/mini_magick.rb in mini_magick-3.2.1 vs lib/mini_magick.rb in mini_magick-3.3
- old
+ new
@@ -131,11 +131,11 @@
# @param validate [Boolean] If false, skips validation of the created image. Defaults to true.
# @yield [IOStream] You can #write bits to this object to create the new Image
# @return [Image] The created image
def create(ext = nil, validate = true, &block)
begin
- tempfile = Tempfile.new(['mini_magick', ext.to_s])
+ tempfile = Tempfile.new(['mini_magick', ext.to_s.downcase])
tempfile.binmode
block.call(tempfile)
tempfile.close
image = self.new(tempfile.path, tempfile)
@@ -162,11 +162,11 @@
@path = input_path
@tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
end
def escaped_path
- "\"#{Pathname.new(@path).to_s}\""
+ Pathname.new(@path).to_s.inspect
end
# Checks to make sure that MiniMagick can read the file and understand it.
#
# This uses the 'identify' command line utility to check the file. If you are having
@@ -286,13 +286,11 @@
# @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
- # 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
+ run_command "identify", output_to.to_s.inspect # 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)
@@ -308,9 +306,14 @@
f = File.new @path
f.binmode
f.read
ensure
f.close if f
+ end
+
+ def mime_type
+ format = self[:format]
+ "image/"+format.downcase
end
# If an unknown method is called then it is sent through the morgrify program
# Look here to find all the commands (http://www.imagemagick.org/script/mogrify.php)
def method_missing(symbol, *args)