mini_magick 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mini_magick might be problematic. Click here for more details.

@@ -4,3 +4,8 @@
4
4
  # 2.) identify doesn't trip over strangley named files
5
5
  # 3.) TempFile uses file extention now (Thanks http://marsorange.com/archives/of-mogrify-ruby-tempfile-dynamic-class-definitions)
6
6
  # 4.) identify commands escape output path correctly
7
+
8
+ == 1.2.3 / 2007-06-15
9
+
10
+ # 1.) Image::from_file doesn't drop the file extension anymore, it and use the image_temp_file correctly
11
+ # 4.) TempFiles are stored as an instance variable in Image instances so they don't get cleaned up prematurely via garbage collection
@@ -7,38 +7,41 @@ require File.join(File.dirname(__FILE__), '/image_temp_file')
7
7
  module MiniMagick
8
8
  class MiniMagickError < RuntimeError; end
9
9
 
10
- VERSION = '1.2.2'
10
+ VERSION = '1.2.3'
11
11
 
12
12
  class Image
13
13
  attr :path
14
+ attr :tempfile
14
15
  attr :output
15
16
 
16
17
  # Class Methods
17
18
  # -------------
18
19
  class <<self
19
- def from_blob(blob)
20
+ def from_blob(blob, extension=nil)
20
21
  begin
21
- @tmp = ImageTempFile.new("minimagick") # Keep reference to the tempfile so garbage collection doesn't destroy it
22
- @tmp.binmode
23
- @tmp.write(blob)
22
+ tempfile = ImageTempFile.new("minimagick#{extension}")
23
+ tempfile.binmode
24
+ tempfile.write(blob)
24
25
  ensure
25
- @tmp.close
26
+ tempfile.close
26
27
  end
27
- return self.new(@tmp.path)
28
+
29
+ return self.new(tempfile.path, tempfile)
28
30
  end
29
31
 
30
32
  # Use this if you don't want to overwrite the image file
31
33
  def from_file(image_path)
32
34
  File.open(image_path, "rb") do |f|
33
- self.from_blob(f.read)
35
+ self.from_blob(f.read, File.extname(image_path))
34
36
  end
35
37
  end
36
38
  end
37
39
 
38
40
  # Instance Methods
39
41
  # ----------------
40
- def initialize(input_path)
42
+ def initialize(input_path, tempfile=nil)
41
43
  @path = input_path
44
+ @tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
42
45
 
43
46
  # Ensure that the file is an image
44
47
  run_command("identify", @path)
@@ -7,6 +7,7 @@ class ImageTest < Test::Unit::TestCase
7
7
  CURRENT_DIR = File.dirname(File.expand_path(__FILE__)) + "/"
8
8
 
9
9
  SIMPLE_IMAGE_PATH = CURRENT_DIR + "simple.gif"
10
+ TIFF_IMAGE_PATH = CURRENT_DIR + "burner.tiff"
10
11
  NOT_AN_IMAGE_PATH = CURRENT_DIR + "not_an_image.php"
11
12
  GIF_WITH_JPG_EXT = CURRENT_DIR + "actually_a_gif.jpg"
12
13
  EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
@@ -49,6 +50,13 @@ class ImageTest < Test::Unit::TestCase
49
50
  assert_equal 55, image[:height]
50
51
  assert_match(/^gif$/i, image[:format])
51
52
  end
53
+
54
+ def test_tiff
55
+ image = Image.new(TIFF_IMAGE_PATH)
56
+ assert_equal "tiff", image[:format].downcase
57
+ assert_equal 317, image[:width]
58
+ assert_equal 275, image[:height]
59
+ end
52
60
 
53
61
  def test_gif_with_jpg_format
54
62
  image = Image.new(GIF_WITH_JPG_EXT)
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0.1
3
3
  specification_version: 1
4
4
  name: mini_magick
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.2.2
7
- date: 2007-06-01 00:00:00 -04:00
6
+ version: 1.2.3
7
+ date: 2007-06-15 00:00:00 -04:00
8
8
  summary: A simple image manipulation library based on ImageMagick.
9
9
  require_paths:
10
10
  - lib