Class MiniMagick::Image
In: lib/mini_magick.rb
Parent: Object

Methods

Attributes

path  [RW]  @return [String] The location of the current working file

Public Class methods

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

@deprecated Please use Image.read instead!

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’.

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

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

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]

Public Instance methods

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.

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 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

Collapse images with sequences to the first frame (ie. animated gifs) and preserve quality

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]

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.

@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. Leave as default if you don‘t care. @return [nil]

Outputs a carriage-return delimited format string for Unix and Windows

If an unknown method is called then it is sent through the mogrify program Look here to find all the commands (www.imagemagick.org/script/mogrify.php)

Gives you raw image data back @return [String] binary string

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]

Check to see if we are running on win32 — we need to escape things differently

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

[Validate]