GithubHelp home page GithubHelp logo

tmorton / minimagick Goto Github PK

View Code? Open in Web Editor NEW

This project forked from minimagick/minimagick

0.0 2.0 0.0 1.32 MB

mini replacement for RMagick

Home Page: http://mini_magick.rubyforge.org/

License: MIT License

Ruby 96.94% Perl 2.98% PHP 0.08%

minimagick's Introduction

MiniMagick

A ruby wrapper for ImageMagick or GraphicsMagick command line.

Tested on the following Rubies: MRI 1.8.7, 1.9.2, 1.9.3, 2.0.0, REE, JRuby, Rubinius.

Build Status

Installation

Add the gem to your Gemfile:

gem "mini_magick"

Why?

I was using RMagick and loving it, but it was eating up huge amounts of memory. Even a simple script would use over 100MB of Ram. On my local machine this wasn't a problem, but on my hosting server the ruby apps would crash because of their 100MB memory limit.

Solution!

Using MiniMagick the ruby processes memory remains small (it spawns ImageMagick's command line program mogrify which takes up some memory as well, but is much smaller compared to RMagick)

MiniMagick gives you access to all the commandline options ImageMagick has (Found here http://www.imagemagick.org/script/mogrify.php)

Examples

Want to make a thumbnail from a file...

image = MiniMagick::Image.open("input.jpg")
image.resize "100x100"
image.write  "output.jpg"

Want to make a thumbnail from a blob...

image = MiniMagick::Image.read(blob)
image.resize "100x100"
image.write  "output.jpg"

Got an incoming IOStream?

image = MiniMagick::Image.read(stream)

Want to make a thumbnail of a remote image?

image = MiniMagick::Image.open("http://www.google.com/images/logos/logo.png")
image.resize "5x5"
image.format "gif"
image.write "localcopy.gif"

Need to combine several options?

image = MiniMagick::Image.open("input.jpg")
image.combine_options do |c|
  c.sample "50%"
  c.rotate "-90>"
end
image.write "output.jpg"

Want to composite two images? Super easy! (Aka, put a watermark on!)

image = Image.open("original.png")
result = image.composite(Image.open("watermark.png", "jpg")) do |c|
  c.gravity "center"
end
result.write "my_output_file.jpg"

Want to manipulate an image at its source (You won't have to write it out because the transformations are done on that file)

image = MiniMagick::Image.new("input.jpg")
image.resize "100x100"

Want to get some meta-information out?

image = MiniMagick::Image.open("input.jpg")
image[:width]               # will get the width (you can also use :height and :format)
image["EXIF:BitsPerSample"] # It also can get all the EXIF tags
image["%m:%f %wx%h"]        # Or you can use one of the many options of the format command

For more on the format command see http://www.imagemagick.org/script/command-line-options.php#format

Want to composite (merge) two images?

first_image = MiniMagick::Image.open "first.jpg"
second_image = MiniMagick::Image.open "second.jpg"
first_image.composite(second_image) do |c|
  c.compose "Over" # OverCompositeOp
  c.geometry "+20+20" # copy second_image onto first_image from (20, 20)
end
first_image.write "output.jpg"

Thinking of switching from RMagick?

Unlike RMagick, MiniMagick is a much thinner wrapper around ImageMagick.

  • To piece together MiniMagick commands is to refer to the Mogrify Documentation. For instance you can use the -flop option as image.flop.
  • Operations on a MiniMagick image tend to happen in-place as image.trim, whereas RMagick has both copying and in-place methods like image.trim and image.trim!.
  • Top open files with MiniMagick you use MiniMagick::Image.open as you would Magick::Image.read. To open a file and directly edit it, use MiniMagick::Image.new.

Windows Users

When passing in a blob or IOStream, Windows users need to make sure they read the file in as binary.

# This way works on Windows
buffer = StringIO.new(File.open(IMAGE_PATH,"rb") { |f| f.read })
MiniMagick::Image.read(buffer)

# You may run into problems doing it this way
buffer = StringIO.new(File.read(IMAGE_PATH))

Using GraphicsMagick

Simply set

MiniMagick.processor = :gm

And you are sorted.

Requirements

You must have ImageMagick or GraphicsMagick installed.

Caveats

Version 3.5 doesn't work in Ruby 1.9.2-p180. If you are running this Ruby version use the 3.4 version of this gem.

minimagick's People

Contributors

2potatocakes avatar 46bit avatar andersondias avatar bensie avatar clowder avatar dcu avatar dicom avatar felixbuenemann avatar for-lesbians avatar fschwahn avatar gmanley avatar gschammah avatar halfbyte avatar hamptonmakes avatar jarmo avatar jf avatar jimneath avatar kaspergrubbe avatar kellyredding avatar kepi avatar kurko avatar lluzak avatar loe avatar mateusg avatar mindreframer avatar probablycorey avatar renchap avatar robertjwhitney avatar thiagofm avatar waydotnet 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.