Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cannikin/mini_magick-1
https://github.com/cannikin/mini_magick-1
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/cannikin/mini_magick-1
- Owner: cannikin
- License: mit
- Created: 2014-09-27T04:01:02.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2010-08-30T19:48:17.000Z (over 14 years ago)
- Last Synced: 2024-10-12T15:22:45.498Z (3 months ago)
- Homepage:
- Size: 1.11 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: MIT-LICENSE
Awesome Lists containing this project
README
= MiniMagick
A ruby wrapper for ImageMagick command line.
== Why?
I was using RMagick and loving it, but it was eating up huge amounts
of memory. A simple script like this...Magick::read("image.jpg") do |f|
f.write("manipulated.jpg")
end...would use over 100 Megs of Ram. On my local machine this wasn't a
problem, but on my hosting server the ruby apps would crash because of
their 100 Meg memory limit.== Solution!
Using MiniMagick the ruby processes memory remains small (it spawns
ImageMagick's command line programs mogrify and composite 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.from_file("input.jpg")
image.resize "100x100"
image.write("output.jpg")Want to make a thumbnail from a blob...
image = MiniMagick::Image.from_blob(blob)
image.resize "100x100"
image.write("output.jpg")Need to combine several options?
image = MiniMagick::Image.from_file("input.jpg")
image.combine_options do |c|
c.sample "50%"
c.rotate "-90>"
end
image.write("output.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.from_file("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 commandFor more on the format command see
http://www.imagemagick.org/script/command-line-options.php#format== Compositing
To create a composite simply call Composite.new with the images you want composite,
the path to the output file and any command line options you may want. Note that the
images should be passed in the order you want them stacked (first image is on top, second
image is in back). You will be returned a MiniMagick::Image instance for the new composited image:image1 = MiniMagick::Image.open('foreground.png')
image2 = MiniMagick::Image.open('background.png')
output_image = MiniMagick::Composite.new(image1, image2, 'jpg', :gravity => 'NorthEast')
output_image.write('combined_image.jpg')The above example would combine the two images into a new JPEG file and, if the two images are
different sizes it will stick the top image into the upper right (north east) corner of the bottom image.
The the image is saved using the standard Image.save method.The 'composite' script has several options, see here: http://www.imagemagick.org/script/composite.php
== Requirements
You must have ImageMagick installed.