pax_global_header 0000666 0000000 0000000 00000000064 12244772740 0014523 g ustar 00root root 0000000 0000000 52 comment=4884a295544a891571fa63ff55ce7276b857d915
minimagick-3.7.0/ 0000775 0000000 0000000 00000000000 12244772740 0013642 5 ustar 00root root 0000000 0000000 minimagick-3.7.0/.gitignore 0000664 0000000 0000000 00000000052 12244772740 0015627 0 ustar 00root root 0000000 0000000 /pkg
coverage
*.lock
.idea
.yardoc
.rvmrc
minimagick-3.7.0/.travis.yml 0000664 0000000 0000000 00000000303 12244772740 0015747 0 ustar 00root root 0000000 0000000 language: ruby
rvm:
- 1.8.7
- 1.9.2
- 1.9.3
- 2.0.0
- ruby-head
- ree
- jruby-18mode
- jruby-19mode
- jruby-20mode
- jruby-head
matrix:
allow_failures:
- rvm: ruby-head
minimagick-3.7.0/Gemfile 0000664 0000000 0000000 00000000047 12244772740 0015136 0 ustar 00root root 0000000 0000000 source "https://rubygems.org"
gemspec
minimagick-3.7.0/MIT-LICENSE 0000664 0000000 0000000 00000002077 12244772740 0015304 0 ustar 00root root 0000000 0000000 Copyright (c) 2005-2013 Corey Johnson probablycorey@gmail.com
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
minimagick-3.7.0/README.md 0000664 0000000 0000000 00000010412 12244772740 0015117 0 ustar 00root root 0000000 0000000 # 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.
[](http://travis-ci.org/minimagick/minimagick)
## Installation
Add the gem to your Gemfile:
```ruby
gem "mini_magick"
```
## Information
* [Rdoc](http://rubydoc.info/github/minimagick/minimagick)
## 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 command line options ImageMagick
has (Found here http://www.imagemagick.org/script/mogrify.php)
## Examples
Want to make a thumbnail from a file...
```ruby
image = MiniMagick::Image.open("input.jpg")
image.resize "100x100"
image.write "output.jpg"
```
Want to make a thumbnail from a blob...
```ruby
image = MiniMagick::Image.read(blob)
image.resize "100x100"
image.write "output.jpg"
```
Got an incoming IOStream?
```ruby
image = MiniMagick::Image.read(stream)
```
Want to make a thumbnail of a remote image?
```ruby
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?
```ruby
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!)
```ruby
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)
```ruby
image = MiniMagick::Image.new("input.jpg")
image.resize "100x100"
```
Want to get some meta-information out?
```ruby
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?
```ruby
first_image = MiniMagick::Image.open "first.jpg"
second_image = MiniMagick::Image.open "second.jpg"
result = 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
result.write "output.jpg"
```
## Thinking of switching from RMagick?
Unlike [RMagick](http://rmagick.rubyforge.org), MiniMagick is a much thinner wrapper around ImageMagick.
* To piece together MiniMagick commands refer to the [Mogrify Documentation](http://www.imagemagick.org/script/mogrify.php). 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!`.
* To 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.
```ruby
# 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
```ruby
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-3.7.0/Rakefile 0000664 0000000 0000000 00000000502 12244772740 0015304 0 ustar 00root root 0000000 0000000 require 'bundler'
Bundler::GemHelper.install_tasks
$:.unshift 'lib'
desc 'Default: run unit tests.'
task :default => [:print_version, :spec]
task :print_version do
puts `mogrify --version`
end
require 'rspec/core/rake_task'
desc "Run specs"
RSpec::Core::RakeTask.new do |t|
t.pattern = "./spec/**/*_spec.rb"
end
minimagick-3.7.0/lib/ 0000775 0000000 0000000 00000000000 12244772740 0014410 5 ustar 00root root 0000000 0000000 minimagick-3.7.0/lib/mini_gmagick.rb 0000664 0000000 0000000 00000000061 12244772740 0017350 0 ustar 00root root 0000000 0000000 require 'mini_magick'
MiniMagick.processor = :gm
minimagick-3.7.0/lib/mini_magick.rb 0000664 0000000 0000000 00000003664 12244772740 0017215 0 ustar 00root root 0000000 0000000 require 'tempfile'
require 'subexec'
require 'stringio'
require 'pathname'
require 'shellwords'
require 'mini_magick/command_builder'
require 'mini_magick/errors'
require 'mini_magick/image'
require 'mini_magick/utilities'
module MiniMagick
class << self
attr_accessor :processor
attr_accessor :processor_path
attr_accessor :timeout
##
# Tries to detect the current processor based if any of the processors exist.
# Mogrify have precedence over gm by default.
#
# === Returns
# * [String] The detected procesor
def choose_processor
if MiniMagick::Utilities.which('mogrify').size > 0
self.processor = 'mogrify'
elsif MiniMagick::Utilities.which('gm').size > 0
self.processor = "gm"
end
end
##
# Discovers the imagemagick version based on mogrify's output.
#
# === Returns
# * The imagemagick version
def image_magick_version
@@version ||= Gem::Version.create(`mogrify --version`.split(" ")[2].split("-").first)
end
##
# The minimum allowed imagemagick version
#
# === Returns
# * The minimum imagemagick version
def minimum_image_magick_version
@@minimum_version ||= Gem::Version.create("6.6.3")
end
##
# Checks whether the imagemagick's version is valid
#
# === Returns
# * [Boolean]
def valid_version_installed?
image_magick_version >= minimum_image_magick_version
end
##
# Picks the right processor if it isn't set and returns whether it's mogrify or not.
#
# === Returns
# * [Boolean]
def mogrify?
self.choose_processor if self.processor.nil?
self.processor == 'mogrify'
end
##
# Picks the right processor if it isn't set and returns whether it's graphicsmagick or not.
#
# === Returns
# * [Boolean]
def gm?
self.choose_processor if self.processor.nil?
self.processor == 'gm'
end
end
end
minimagick-3.7.0/lib/mini_magick/ 0000775 0000000 0000000 00000000000 12244772740 0016657 5 ustar 00root root 0000000 0000000 minimagick-3.7.0/lib/mini_magick/command_builder.rb 0000664 0000000 0000000 00000011545 12244772740 0022336 0 ustar 00root root 0000000 0000000 module MiniMagick
class CommandBuilder
MOGRIFY_COMMANDS = %w{adaptive-blur adaptive-resize adaptive-sharpen adjoin affine alpha annotate antialias append attenuate authenticate auto-gamma auto-level auto-orient backdrop background bench bias black-point-compensation black-threshold blend blue-primary blue-shift blur border bordercolor borderwidth brightness-contrast cache caption cdl channel charcoal chop clamp clip clip-mask clip-path clone clut coalesce colorize colormap color-matrix colors colorspace combine comment compose composite compress contrast contrast-stretch convolve crop cycle debug decipher deconstruct define delay delete density depth descend deskew despeckle direction displace display dispose dissimilarity-threshold dissolve distort dither draw duplicate edge emboss encipher encoding endian enhance equalize evaluate evaluate-sequence extent extract family features fft fill filter flatten flip floodfill flop font foreground format frame function fuzz fx gamma gaussian-blur geometry gravity green-primary hald-clut help highlight-color iconGeometry iconic identify ift immutable implode insert intent interlace interpolate interline-spacing interword-spacing kerning label lat layers level level-colors limit linear-stretch linewidth liquid-rescale list log loop lowlight-color magnify map mask mattecolor median metric mode modulate monitor monochrome morph morphology mosaic motion-blur name negate noise normalize opaque ordered-dither orient page paint path pause pen perceptible ping pointsize polaroid poly posterize precision preview print process profile quality quantize quiet radial-blur raise random-threshold red-primary regard-warnings region remap remote render repage resample resize respect-parentheses reverse roll rotate sample sampling-factor scale scene screen seed segment selective-blur separate sepia-tone set shade shadow shared-memory sharpen shave shear sigmoidal-contrast silent size sketch smush snaps solarize sparse-color splice spread statistic stegano stereo stretch strip stroke strokewidth style subimage-search swap swirl synchronize taint text-font texture threshold thumbnail tile tile-offset tint title transform transparent transparent-color transpose transverse treedepth trim type undercolor unique-colors units unsharp update verbose version view vignette virtual-pixel visual watermark wave weight white-point white-threshold window window-group write}
IMAGE_CREATION_OPERATORS = %w{canvas caption gradient label logo pattern plasma radial radient rose text tile xc }
def initialize(tool, *options)
@tool = tool
@args = []
options.each { |arg| push(arg) }
end
def command
com = "#{@tool} #{args.join(' ')}".strip
com = "#{MiniMagick.processor} #{com}" unless MiniMagick.mogrify?
com = File.join MiniMagick.processor_path, com unless MiniMagick.processor_path.nil?
com.strip
end
def escape_string_windows(value)
# For Windows, ^ is the escape char, equivalent to \ in Unix.
escaped = value.gsub(/\^/, '^^').gsub(/>/, '^>')
if escaped !~ /^".+"$/ && escaped.include?("'")
escaped.inspect
else
escaped
end
end
def args
if !MiniMagick::Utilities.windows?
@args.map(&:shellescape)
else
@args.map { |arg| escape_string_windows(arg) }
end
end
# Add each mogrify command in both underscore and dash format
MOGRIFY_COMMANDS.each do |mogrify_command|
# Example of what is generated here:
#
# def auto_orient(*options)
# add_command("auto-orient", *options)
# self
# end
# alias_method :"auto-orient", :auto_orient
dashed_command = mogrify_command.to_s.gsub("_","-")
underscored_command = mogrify_command.to_s.gsub("-","_")
define_method(underscored_command) do |*options|
add_command(__method__.to_s.gsub("_","-"), *options)
self
end
alias_method dashed_command, underscored_command
end
def format(*options)
raise Error, "You must call 'format' on the image object directly!"
end
IMAGE_CREATION_OPERATORS.each do |operator|
define_method operator do |*options|
add_creation_operator(__method__.to_s, *options)
self
end
end
def +(*options)
push(@args.pop.gsub(/^-/, '+'))
if options.any?
options.each do |o|
push o
end
end
end
def add_command(command, *options)
push "-#{command}"
if options.any?
options.each do |o|
push o
end
end
end
def add_creation_operator(command, *options)
creation_command = command
if options.any?
options.each do |option|
creation_command << ":#{option}"
end
end
push creation_command
end
def push(arg)
@args << arg.to_s.strip
end
alias :<< :push
end
end
minimagick-3.7.0/lib/mini_magick/errors.rb 0000664 0000000 0000000 00000000135 12244772740 0020517 0 ustar 00root root 0000000 0000000 module MiniMagick
class Error < RuntimeError; end
class Invalid < StandardError; end
end
minimagick-3.7.0/lib/mini_magick/image.rb 0000664 0000000 0000000 00000036607 12244772740 0020302 0 ustar 00root root 0000000 0000000 module MiniMagick
class Image
# @return [String] The location of the current working file
attr_accessor :path
def path_for_windows_quote_space(path)
path = Pathname.new(@path).to_s
# For Windows, if a path contains space char, you need to quote it, otherwise you SHOULD NOT quote it.
# If you quote a path that does not contains space, it will not work.
@path.include?(' ') ? path.inspect : path
end
def path
MiniMagick::Utilities.windows? ? path_for_windows_quote_space(@path) : @path
end
def path=(path)
@path = path
end
# Class Methods
# -------------
class << self
# This is the primary loading method used by all of the other class methods.
#
# Use this to pass in a stream object. Must respond to Object#read(size) or be a binary string object (BLOBBBB)
#
# As a change from the old API, please try and use IOStream objects. They are much, much better and more efficient!
#
# Probably easier to use the #open method if you want to open a file or a URL.
#
# @param stream [IOStream, String] Some kind of stream object that needs to be read or is a binary String blob!
# @param ext [String] A manual extension to use for reading the file. Not required, but if you are having issues, give this a try.
# @return [Image]
def read(stream, ext = nil)
if stream.is_a?(String)
stream = StringIO.new(stream)
elsif stream.is_a?(StringIO)
# Do nothing, we want a StringIO-object
elsif stream.respond_to? :path
if File.respond_to?(:binread)
stream = StringIO.new File.binread(stream.path.to_s)
else
stream = StringIO.new File.open(stream.path.to_s,"rb") { |f| f.read }
end
end
create(ext) do |f|
while chunk = stream.read(8192)
f.write(chunk)
end
end
end
# @deprecated Please use Image.read instead!
def from_blob(blob, ext = nil)
warn "Warning: MiniMagick::Image.from_blob method is deprecated. Instead, please use Image.read"
create(ext) { |f| f.write(blob) }
end
# Creates an image object from a binary string blob which contains raw pixel data (i.e. no header data).
#
# === Returns
#
# * [Image] The loaded image.
#
# === Parameters
#
# * [blob] String -- Binary string blob containing raw pixel data.
# * [columns] Integer -- Number of columns.
# * [rows] Integer -- Number of rows.
# * [depth] Integer -- Bit depth of the encoded pixel data.
# * [map] String -- A code for the mapping of the pixel data. Example: 'gray' or 'rgb'.
# * [format] String -- The file extension of the image format to be used when creating the image object. Defaults to 'png'.
#
def import_pixels(blob, columns, rows, depth, map, format="png")
# Create an image object with the raw pixel data string:
image = create(".dat", validate = false) { |f| f.write(blob) }
# Use ImageMagick to convert the raw data file to an image file of the desired format:
converted_image_path = image.path[0..-4] + format
arguments = ["-size", "#{columns}x#{rows}", "-depth", "#{depth}", "#{map}:#{image.path}", "#{converted_image_path}"]
cmd = CommandBuilder.new("convert", *arguments) #Example: convert -size 256x256 -depth 16 gray:blob.dat blob.png
image.run(cmd)
# Update the image instance with the path of the properly formatted image, and return:
image.path = converted_image_path
image
end
# Opens a specific image file either on the local file system or at a URI.
#
# Use this if you don't want to overwrite the image file.
#
# Extension is either guessed from the path or you can specify it as a second parameter.
#
# If you pass in what looks like a URL, we require 'open-uri' before opening it.
#
# @param file_or_url [String] Either a local file path or a URL that open-uri can read
# @param ext [String] Specify the extension you want to read it as
# @return [Image] The loaded image
def open(file_or_url, ext = nil)
file_or_url = file_or_url.to_s # Force it to be a String... hell or highwater
if file_or_url.include?("://")
require 'open-uri'
ext ||= File.extname(URI.parse(file_or_url).path)
Kernel::open(file_or_url) do |f|
self.read(f, ext)
end
else
ext ||= File.extname(file_or_url)
File.open(file_or_url, "rb") do |f|
self.read(f, ext)
end
end
end
# @deprecated Please use MiniMagick::Image.open(file_or_url) now
def from_file(file, ext = nil)
warn "Warning: MiniMagick::Image.from_file is now deprecated. Please use Image.open"
open(file, ext)
end
# Used to create a new Image object data-copy. Not used to "paint" or that kind of thing.
#
# Takes an extension in a block and can be used to build a new Image object. Used
# by both #open and #read to create a new object! Ensures we have a good tempfile!
#
# @param ext [String] Specify the extension you want to read it as
# @param validate [Boolean] If false, skips validation of the created image. Defaults to true.
# @yield [IOStream] You can #write bits to this object to create the new Image
# @return [Image] The created image
def create(ext = nil, validate = true, &block)
begin
tempfile = Tempfile.new(['mini_magick', ext.to_s.downcase])
tempfile.binmode
block.call(tempfile)
tempfile.close
image = self.new(tempfile.path, tempfile)
if validate and !image.valid?
raise MiniMagick::Invalid
end
return image
ensure
tempfile.close if tempfile
end
end
end
# Create a new MiniMagick::Image object
#
# _DANGER_: The file location passed in here is the *working copy*. That is, it gets *modified*.
# you can either copy it yourself or use the MiniMagick::Image.open(path) method which creates a
# temporary file for you and protects your original!
#
# @param input_path [String] The location of an image file
# @todo Allow this to accept a block that can pass off to Image#combine_options
def initialize(input_path, tempfile = nil)
@path = input_path
@tempfile = tempfile # ensures that the tempfile will stick around until this image is garbage collected.
end
# Checks to make sure that MiniMagick can read the file and understand it.
#
# This uses the 'identify' command line utility to check the file. If you are having
# issues with this, then please work directly with the 'identify' command and see if you
# can figure out what the issue is.
#
# @return [Boolean]
def valid?
run_command("identify", path)
true
rescue MiniMagick::Invalid
false
end
# A rather low-level way to interact with the "identify" command. No nice API here, just
# the crazy stuff you find in ImageMagick. See the examples listed!
#
# @example
# image["format"] #=> "TIFF"
# image["height"] #=> 41 (pixels)
# image["width"] #=> 50 (pixels)
# image["colorspace"] #=> "DirectClassRGB"
# image["dimensions"] #=> [50, 41]
# image["size"] #=> 2050 (bits)
# image["original_at"] #=> 2005-02-23 23:17:24 +0000 (Read from Exif data)
# image["EXIF:ExifVersion"] #=> "0220" (Can read anything from Exif)
#
# @param format [String] A format for the "identify" command
# @see For reference see http://www.imagemagick.org/script/command-line-options.php#format
# @return [String, Numeric, Array, Time, Object] Depends on the method called! Defaults to String for unknown commands
def [](value)
# Why do I go to the trouble of putting in newlines? Because otherwise animated gifs screw everything up
case value.to_s
when "colorspace"
run_command("identify", "-format", '%r\n', path).split("\n")[0].strip
when "format"
run_command("identify", "-format", '%m\n', path).split("\n")[0]
when "height"
run_command("identify", "-format", '%h\n', path).split("\n")[0].to_i
when "width"
run_command("identify", "-format", '%w\n', path).split("\n")[0].to_i
when "dimensions"
run_command("identify", "-format", MiniMagick::Utilities.windows? ? '"%w %h\n"' : '%w %h\n', path).split("\n")[0].split.map{|v|v.to_i}
when "size"
File.size(path) # Do this because calling identify -format "%b" on an animated gif fails!
when "original_at"
# Get the EXIF original capture as a Time object
Time.local(*self["EXIF:DateTimeOriginal"].split(/:|\s+/)) rescue nil
when /^EXIF\:/i
result = run_command('identify', '-format', "%[#{value}]", path).chomp
if result.include?(",")
read_character_data(result)
else
result
end
else
run_command('identify', '-format', value, path).split("\n")[0]
end
end
# Sends raw commands to imagemagick's `mogrify` command. The image path is automatically appended to the command.
#
# Remember, we are always acting on this instance of the Image when messing with this.
#
# @return [String] Whatever the result from the command line is. May not be terribly useful.
def <<(*args)
run_command("mogrify", *args << path)
end
# This is used to change the format of the image. That is, from "tiff to jpg" or something like that.
# Once you run it, the instance is pointing to a new file with a new extension!
#
# *DANGER*: This renames the file that the instance is pointing to. So, if you manually opened the
# file with Image.new(file_path)... then that file is DELETED! If you used Image.open(file) then
# you are ok. The original file will still be there. But, any changes to it might not be...
#
# Formatting an animation into a non-animated type will result in ImageMagick creating multiple
# pages (starting with 0). You can choose which page you want to manipulate. We default to the
# first page.
#
# If you would like to convert between animated formats, pass nil as your
# page and ImageMagick will copy all of the pages.
#
# @param format [String] The target format... like 'jpg', 'gif', 'tiff', etc.
# @param page [Integer] If this is an animated gif, say which 'page' you want
# with an integer. Default 0 will convert only the first page; 'nil' will
# convert all pages.
# @return [nil]
def format(format, page = 0)
c = CommandBuilder.new('mogrify', '-format', format)
yield c if block_given?
if page
c << "#{path}[#{page}]"
else
c << path
end
run(c)
old_path = path
self.path = path.sub(/(\.\w*)?$/, ".#{format}")
File.delete(old_path) if old_path != path
unless File.exists?(path)
raise MiniMagick::Error, "Unable to format to #{format}"
end
end
# Collapse images with sequences to the first frame (ie. animated gifs) and
# preserve quality
def collapse!
run_command("mogrify", "-quality", "100", "#{path}[0]")
end
# Writes the temporary file out to either a file location (by passing in a String) or by
# passing in a Stream that you can #write(chunk) to repeatedly
#
# @param output_to [IOStream, String] Some kind of stream object that needs to be read or a file path as a String
# @return [IOStream, Boolean] If you pass in a file location [String] then you get a success boolean. If its a stream, you get it back.
# Writes the temporary image that we are using for processing to the output path
def write(output_to)
if output_to.kind_of?(String) || !output_to.respond_to?(:write)
FileUtils.copy_file path, output_to
run_command "identify", MiniMagick::Utilities.windows? ? path_for_windows_quote_space(output_to.to_s) : output_to.to_s # Verify that we have a good image
else # stream
File.open(path, "rb") do |f|
f.binmode
while chunk = f.read(8192)
output_to.write(chunk)
end
end
output_to
end
end
# Gives you raw image data back
# @return [String] binary string
def to_blob
f = File.new path
f.binmode
f.read
ensure
f.close if f
end
def mime_type
format = self[:format]
"image/" + format.to_s.downcase
end
# If an unknown method is called then it is sent through the mogrify program
# Look here to find all the commands (http://www.imagemagick.org/script/mogrify.php)
def method_missing(symbol, *args)
combine_options do |c|
c.send(symbol, *args)
end
end
# You can use multiple commands together using this method. Very easy to use!
#
# @example
# image.combine_options do |c|
# c.draw "image Over 0,0 10,10 '#{MINUS_IMAGE_PATH}'"
# c.thumbnail "300x500>"
# c.background background
# end
#
# @yieldparam command [CommandBuilder]
def combine_options(tool = "mogrify", &block)
c = CommandBuilder.new(tool)
c << path if tool.to_s == "convert"
block.call(c)
c << path
run(c)
end
def composite(other_image, output_extension = 'jpg', &block)
begin
second_tempfile = Tempfile.new(output_extension)
second_tempfile.binmode
ensure
second_tempfile.close
end
command = CommandBuilder.new("composite")
block.call(command) if block
command.push(other_image.path)
command.push(self.path)
command.push(second_tempfile.path)
run(command)
return Image.new(second_tempfile.path, second_tempfile)
end
def run_command(command, *args)
if command == 'identify'
args.unshift '-ping' # -ping "efficiently determine image characteristics."
args.unshift '-quiet' if MiniMagick.mogrify? # graphicsmagick has no -quiet option.
end
run(CommandBuilder.new(command, *args))
end
def run(command_builder)
command = command_builder.command
sub = Subexec.run(command, :timeout => MiniMagick.timeout)
if sub.exitstatus != 0
# Clean up after ourselves in case of an error
destroy!
# Raise the appropriate error
if sub.output =~ /no decode delegate/i || sub.output =~ /did not return an image/i
raise Invalid, sub.output
else
# TODO: should we do something different if the command times out ...?
# its definitely better for logging.. otherwise we dont really know
raise Error, "Command (#{command.inspect.gsub("\\", "")}) failed: #{{:status_code => sub.exitstatus, :output => sub.output}.inspect}"
end
else
sub.output
end
end
def destroy!
return if @tempfile.nil?
File.unlink(path) if File.exists?(path)
@tempfile = nil
end
private
# Sometimes we get back a list of character values
def read_character_data(list_of_characters)
chars = list_of_characters.gsub(" ", "").split(",")
result = ""
chars.each do |val|
result << ("%c" % val.to_i)
end
result
end
end
end
minimagick-3.7.0/lib/mini_magick/utilities.rb 0000664 0000000 0000000 00000001477 12244772740 0021230 0 ustar 00root root 0000000 0000000 require 'rbconfig'
module MiniMagick
module Utilities
class << self
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable? exe
}
end
return nil
end
# Finds out if the host OS is windows
def windows?
RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/
end
def windows_escape(cmdline)
'"' + cmdline.gsub(/\\(?=\\*\")/, "\\\\\\").gsub(/\"/, "\\\"").gsub(/\\$/, "\\\\\\").gsub("%", "%%") + '"'
end
end
end
end
minimagick-3.7.0/lib/mini_magick/version.rb 0000664 0000000 0000000 00000000052 12244772740 0020666 0 ustar 00root root 0000000 0000000 module MiniMagick
VERSION = "3.7.0"
end
minimagick-3.7.0/mini_magick.gemspec 0000664 0000000 0000000 00000002007 12244772740 0017455 0 ustar 00root root 0000000 0000000 # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "mini_magick/version"
Gem::Specification.new do |s|
s.name = "mini_magick"
s.version = MiniMagick::VERSION
s.platform = Gem::Platform::RUBY
s.summary = "Manipulate images with minimal use of memory via ImageMagick / GraphicsMagick"
s.description = ""
s.requirements << "You must have ImageMagick or GraphicsMagick installed"
s.authors = ["Corey Johnson", "Hampton Catlin", "Peter Kieltyka"]
s.email = ["probablycorey@gmail.com", "hcatlin@gmail.com", "peter@nulayer.com"]
s.homepage = "https://github.com/minimagick/minimagick"
s.files = Dir['README.rdoc', 'VERSION', 'MIT-LICENSE', 'Rakefile', 'lib/**/*']
s.test_files = Dir['test/**/*']
s.require_paths = ["lib"]
s.add_runtime_dependency('subexec', ['~> 0.2.1'])
s.add_development_dependency('rake')
s.add_development_dependency('test-unit')
s.add_development_dependency('rspec')
s.add_development_dependency('mocha')
end
minimagick-3.7.0/spec/ 0000775 0000000 0000000 00000000000 12244772740 0014574 5 ustar 00root root 0000000 0000000 minimagick-3.7.0/spec/files/ 0000775 0000000 0000000 00000000000 12244772740 0015676 5 ustar 00root root 0000000 0000000 minimagick-3.7.0/spec/files/actually_a_gif.jpg 0000664 0000000 0000000 00000005235 12244772740 0021350 0 ustar 00root root 0000000 0000000 GIF89a2
#
!!"!#
$!%($)$
)'*++%,% ,),*
,*,,-*"-3.01322-3&3)3+#3-441#445%5.+53627539+96
96:5:8
:8;,#;3+<$<%<2$=
= =9?"
?81@<
A$A<A=B-!B61CC&C4%C6*C9#D*DA;E9,E;2E@EAGF@HCJ,J8&JD%K2$K6*K:+K<2L0L9LG@MB6MF-MJFMLINE9P.POLQ@,QF;R+RL%RQMS4%S7(S<0SA3T1T;+TH,bOBc`]d@.dD2dJ9dZJd]fa@i?*i]Qi^JjC.jcDkE2kbSkgalI4lM;lVHlbJleZlicnQCnYEnojoqepF4pcXqI5qQ7qoirUBreTrkKsmTtM9tZFtrmuQ;v\HvqTxN9y]Jyumzt[zva{S=|cQ|tT|zc|{t|}j}V@}Y:}YB}n]}p~x]aMkU?W@vU}uhxWj]HfScV7\D~^bKczaGcz^FgPkYp^cJjTfLhNkR{mSqVxsY !
, 2 ،[9lĈq*BŎ(Rá@Xq"940b0q[s
BQX*̙F.p§A2>5.E
*T $Yv0"Pmx$\bV˖'k'P0A Tp1W7t0ajOQ5&7T P )
]xR%Jo-'94i0kD
T摰uٓo[G'uu~{!oLoéP9C :icty)˗_ӛ%Đ 26L;DvYn qRL`BEh%B6LrMtaSݧYo!0a2$CI"M0.1Toa^9P)ȱ#26#XZ#%WnwV
p[+t䃘mE/踃N( ,p)!uf
8P4I#6| ]0a'>
9i~H(p 2uZ&]Ŝb(h
]p
-\.fE1h798ו*WI'<@FWi!`b9U:cDTB"iR̨Xh2L!hAo(´WQMal_fH
w .I"Δ3*;}R
%G>LEm25h SX
B
,|F\̃J*ݙ! 0ބxNp%M F.ư#Jx" Ҁ;D lW]Ԅ7aA8CO.p ; pQQ00J=
+gpy8`4CE
0:C><