lib/mini_magick.rb in mini_magick-1.2.2 vs lib/mini_magick.rb in mini_magick-1.2.3
- old
+ new
@@ -5,41 +5,44 @@
require File.join(File.dirname(__FILE__), '/image_temp_file')
module MiniMagick
class MiniMagickError < RuntimeError; end
- VERSION = '1.2.2'
+ VERSION = '1.2.3'
class Image
attr :path
+ attr :tempfile
attr :output
# Class Methods
# -------------
class <<self
- def from_blob(blob)
+ def from_blob(blob, extension=nil)
begin
- @tmp = ImageTempFile.new("minimagick") # Keep reference to the tempfile so garbage collection doesn't destroy it
- @tmp.binmode
- @tmp.write(blob)
+ tempfile = ImageTempFile.new("minimagick#{extension}")
+ tempfile.binmode
+ tempfile.write(blob)
ensure
- @tmp.close
+ tempfile.close
end
- return self.new(@tmp.path)
+
+ return self.new(tempfile.path, tempfile)
end
# Use this if you don't want to overwrite the image file
def from_file(image_path)
File.open(image_path, "rb") do |f|
- self.from_blob(f.read)
+ self.from_blob(f.read, File.extname(image_path))
end
end
end
# Instance Methods
# ----------------
- def initialize(input_path)
+ def initialize(input_path, tempfile=nil)
@path = input_path
+ @tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
# Ensure that the file is an image
run_command("identify", @path)
end