0.01
No commit activity in last 3 years
No release in over 3 years
Simple yet powerful wrapper around imagemagick cli tools for reading metadata and transcoding images.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 0.9.2
~> 2.9
 Project Readme

Streamio Magick ###############

Simple yet powerful wrapper around imagemagick cli tools for reading metadata and transcoding images.

Installation

(sudo) gem install streamio-magick

You also need to make sure to have imagemagick installed and that the commands identify and convert are available to the ruby process.

This version is written against an imagemagick build from august 2010. So no guaranteed compatability with much earlier (or much later) versions.

Usage

Require the gem

require 'rubygems'
require 'streamio-magick'

Reading Metadata

image = Magick::Image.new("path/to/image.png")

image.width # 640 (width of the image in pixels)
image.height # 480 (height of the image in pixels)
image.size # 455546 (filesize in bytes)
image.codec # "PNG"

image.valid? # true (would be false if identify fails to read the image)

Transcoding

First argument is the output file path.

image.transcode("image.jpg") # Transcode to jpg format

Give custom command line options for the convert command with a string.

image.transcode("image.jpg", "-resize 320x240")

The transcode function returns an Image object for the encoded file.

transcoded_image = image.transcode("image.jpg", "-resize 320x240")
transcoded_image.width # 320
transcoded_image.height # 240
transcoded_image.codec # "JPEG"

Rescue from Magick::Error if something goes wrong during transcoding.

begin
  image.transcode("image.jpg")
rescue Magick::Error => e
  # handle error
end

Copyright

Copyright (c) Streamio Networks AB. See LICENSE for details.