Class RMagickTransformationScript
In: lib/asset_compiler/rmagick_transformation_script.rb
Parent: Object

Holds a reference to an instance of Magick::Image and manages operations on it. Used to provide a more consistent, higher-level api than is given by RMagick.

ImageTransformationScript automatically invokes Ruby’s garbage collector by calling GC.start upon instantiating a Magick::Image object. To bypass this, set the GC environment variable to ‘no’.

Methods

crop_to   darken   greyscale   icc_profile   icm_profile   lighten   new   read   size_to_fit   tint   unsharp_mask   write  

Constants

GRAVITY_TYPES = { :none => Magick::ForgetGravity, :northwest => Magick::NorthWestGravity, :north => Magick::NorthGravity, :northeast => Magick::NorthEastGravity, :west => Magick::WestGravity, :center => Magick::CenterGravity, :east => Magick::EastGravity, :southwest => Magick::SouthWestGravity, :south => Magick::SouthGravity, :southeast => Magick::SouthEastGravity

Public Class methods

Initialize an ImageTransformationScript where img is either a path to an image or an instance of Magick::Image.

Public Instance methods

Resizes the image proportionally to fit the smaller dimension, then crops excess. Optionally, a gravity setting may be provided. From the RMagick docs:

  Gravity provides a convenient way to locate objects irrespective of the size of the
  bounding region, in other words, you don't need to provide absolute coordinates in
  order to position an object.

The default gravity setting is :center. Available settings are:

:none
don’t use gravity
:northwest
crop to northwest
:north
crop to north - good for vertical images
:northeast
crop to northeast
:west
crop to west
:center
crop to center - default
:east
crop to east
:southwest
crop to southwest
:south
crop to south
:southeast
crop to southeast

Usage:

  img.crop_to '64x64'         # crops to center, 64x64 pixels
  img.crop_to '64x64', :north # crops to north - common for thumbnailing portraits

Darkens the image. Defaults to a blend factor of 25%.

  img.darken      # darkens the image 25%.
  img.darken 0.40 # darkens the image 40%.

Converts the image to greyscale.

  img.greyscale           # uses default overlay of #aa9955.
  img.greyscale '#aaaaaa' # uses specified overlay.

Applies an ICC profile to the image. Requires path which is a path to a file containing a valid ICC profile.

  img.icc_profile 'srgb.icc'

Applies an ICM profile to the image. Requires path which is a path to a file containing a valid ICM profile.

  img.icm_profile 'srgb.icm'

Lightens the image. Defaults to a blend factor of 25%.

  img.lighten      # lightens the image 25%.
  img.lighten 0.40 # lightens the image 40%.

Read an image from a file specified by src and return a Magick::Image instance.

Resizes the image to fit within the constraints specified by dimensions where dimensions is a String in the format of ‘WIDTHxLENGTH’.

  img.size_to_fit '64x64'

Tints the image according to the following parameters:

  • r Blending factor for the red channel
  • g Blending factor for the green channel
  • b Blending factor for the blue channel
  • overlay Color to tint the image img.tint 0.25, 0.25, 0.25, ffffff # lightens the image 25%

Sharpen only the edges of the image. Parameters are:

  • rad Radius: how big an edge can be
  • sig Sigma weight for gaussian: leave it at 1.0.
  • blend Blending factor: how much sharpening to apply as a percentage
  • thresh Threshold: how different 2 pixels must be to qualify as an edge img.unsharp_mask 0.5, 1.0, 0.5, 0.25

Write the image to a specified path, target.

[Validate]