Skip to content

Instantly share code, notes, and snippets.

@zhangyuan
Last active December 19, 2015 08:19
Show Gist options
  • Select an option

  • Save zhangyuan/5924833 to your computer and use it in GitHub Desktop.

Select an option

Save zhangyuan/5924833 to your computer and use it in GitHub Desktop.
Get Image format and characteristics with identify
@zhangyuan
Copy link
Author

Use MiniMagick to fetch image dimensions.

post = Post.find 1234
image = Tempfile.new(RUBY_VERSION < '1.9' ? "Image": ['Image', ".jpg"])
image.binmode
image.write post.image.file.read
image.close

image = ::MiniMagick::Image.new(image.path, image)
image['dimensions']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment