GithubHelp home page GithubHelp logo

imclab / streamio-magick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from streamio/streamio-magick

0.0 2.0 0.0 328 KB

Simple yet powerful ruby imagemagick wrapper for reading metadata and transcoding images

License: MIT License

streamio-magick's Introduction

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.

streamio-magick's People

Contributors

dbackeus avatar stakach avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.