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

Methods

==   []   attribute   collapse!   combine_options   composite   create   destroy!   eql?   format   frames   get_pixels   hash   identify   import_pixels   info   layer?   layers   method_missing   mogrify   new   open   pages   read   respond_to_missing?   run_command   to_blob   valid?   validate!   write  

Classes and Modules

Class MiniMagick::Image::Info

Attributes

path  [R]  @return [String] The location of the current working file
tempfile  [R]  @return [Tempfile] The underlying temporary file

Public Class methods

@private @!macro [attach] attribute

  @!attribute [r] $1

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 [Tempfile] You can write bits to this object to create the new

  Image

@return [MiniMagick::Image] The created image

Creates an image object from a binary string blob which contains raw pixel data (i.e. no header data).

@param blob [String] Binary string blob containing raw pixel data. @param columns [Integer] Number of columns. @param rows [Integer] Number of rows. @param depth [Integer] Bit depth of the encoded pixel data. @param map [String] A code for the mapping of the pixel data. Example:

  'gray' or 'rgb'.

@param format [String] The file extension of the image format to be

  used when creating the image object.

Defaults to ‘png’. @return [MiniMagick::Image] The loaded image.

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 {.open} which creates a temporary file for you and protects your original.

@param input_path [String, Pathname] The location of an image file @yield [MiniMagick::Tool::Mogrify] If block is given, {combine_options}

  is called.

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.

@param path_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 @param options [Hash] Specify options for the open method @return [MiniMagick::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 read(size) or be a binary string object (BLOBBBB)

Probably easier to use the {.open} method if you want to open a file or a URL.

@param stream [read, 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 [MiniMagick::Image]

Public Instance methods

Use this method if you want to access raw Identify‘s format API.

@example

   image["%w %h"]       #=> "250 450"
   image["%r"]          #=> "DirectClass sRGB"

@param value [String] @see www.imagemagick.org/script/escape.php @return [String]

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

@param frame [Integer] The frame to which to collapse to, defaults to `0`. @return [self]

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 "blue"
  end

@yield [MiniMagick::Tool::Mogrify] @see www.imagemagick.org/script/mogrify.php @return [self]

@example

 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"

@see www.imagemagick.org/script/composite.php

Destroys the tempfile (created by {.open}) if it exists.

eql?(other)

Alias for #==

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.

@param read_opts [Hash] Any read options to be passed to ImageMagick

  for example: image.format('jpg', page, {density: '300'})

@yield [MiniMagick::Tool::Convert] It optionally yields the command,

  if you want to add something.

@return [self]

frames()

Alias for layers

Returns a matrix of pixels from the image. The matrix is constructed as an array (1) of arrays (2) of arrays (3) of unsigned integers:

1) one for each row of pixels 2) one for each column of pixels 3) three elements in the range 0-255, one for each of the RGB color channels

@example

  img = MiniMagick::Image.open 'image.jpg'
  pixels = img.get_pixels
  pixels[3][2][1] # the green channel value from the 4th-row, 3rd-column pixel

It can also be called after applying transformations:

@example

  img = MiniMagick::Image.open 'image.jpg'
  img.crop '20x30+10+5'
  img.colorspace 'Gray'
  pixels = img.get_pixels

In this example, all pixels in pix should now have equal R, G, and B values.

@return [Array] Matrix of each color of each pixel

Runs `identify` on itself. Accepts an optional block for adding more options to `identify`.

@example

  image = MiniMagick::Image.open("image.jpg")
  image.identify do |b|
    b.verbose
  end # runs `identify -verbose image.jpg`

@return [String] Output from `identify` @yield [MiniMagick::Tool::Identify]

info(value)

Alias for #[]

Returns layers of the image. For example, JPEGs are 1-layered, but formats like PSDs, GIFs and PDFs can have multiple layers/frames/pages.

@example

  image = MiniMagick::Image.new("document.pdf")
  image.pages.each_with_index do |page, idx|
    page.write("page#{idx}.pdf")
  end

@return [Array<MiniMagick::Image>]

If an unknown method is called then it is sent through the mogrify program.

@see www.imagemagick.org/script/mogrify.php @return [self]

pages()

Alias for layers

Returns raw image data.

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

Runs `identify` on the current image, and raises an error if it doesn‘t pass.

@raise [MiniMagick::Invalid]

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 [String, Pathname, read] Some kind of stream object

  that needs to be read or a file path as a String

[Validate]