Permalink
Browse files

Merge pull request #44 from kurko/mime_type

Created MiniMagick#mime_type method, test unit included
  • Loading branch information...
2 parents fec940a + 2b37f64 commit 50a81e0e2f0cfc35bfdebc45474600c9342cd308 @hcatlin hcatlin committed Jun 2, 2011
Showing with 20 additions and 0 deletions.
  1. +5 −0 lib/mini_magick.rb
  2. +15 −0 test/image_test.rb
  3. BIN test/output.png
  4. BIN test/png.png
View
@@ -280,6 +280,11 @@ def to_blob
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)
View
@@ -18,6 +18,7 @@ class ImageTest < Test::Unit::TestCase
EXIF_IMAGE_PATH = CURRENT_DIR + "trogdor.jpg"
CAP_EXT_PATH = CURRENT_DIR + "trogdor_capitalized.JPG"
ANIMATION_PATH = CURRENT_DIR + "animation.gif"
+ PNG_PATH = CURRENT_DIR + "png.png"
def test_image_from_blob
File.open(SIMPLE_IMAGE_PATH, "rb") do |f|
@@ -293,4 +294,18 @@ def test_throw_format_error
end
image.destroy!
end
+
+ def test_mime_type
+ gif = Image.open(SIMPLE_IMAGE_PATH)
+ jpeg = Image.open(EXIF_IMAGE_PATH)
+ png = Image.open(PNG_PATH)
+ tiff = Image.open(TIFF_IMAGE_PATH)
+ hidden_gif = Image.open(GIF_WITH_JPG_EXT)
+
+ assert_equal "image/gif", gif.mime_type
+ assert_equal "image/jpeg", jpeg.mime_type
+ assert_equal "image/png", png.mime_type
+ assert_equal "image/tiff", tiff.mime_type
+ assert_equal "image/gif", hidden_gif.mime_type
+ end
end
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 50a81e0

Please sign in to comment.