Method: FreeImage::Modify#enlarge_canvas

Defined in:
lib/free-image/modules/modify.rb

#enlarge_canvas(left, top, right, bottom, color, options = 0, &block) ⇒ Object

:call-seq:

image.enlarge_canvas(left, top, right, bottom, color, options = 0) -> bitmap
image.enlarge_canvas(left, top, right, bottom, color, options = 0) {|img| block} -> bitmap

Enlarges or shrinks an image selectively per side and fills newly added areas with the specified background color. The common use case is to add borders to an image.

To add a border to any of the image’s sides, a positive integer value must be passed in any of the parameters left, top, right or bottom. This value represents the border’s width in pixels. Newly created parts of the image (the border areas) are filled with the specified color.

Specifying a negative integer value for a certain side, will shrink or crop the image on this side. Consequently, specifying zero for a certain side will not change the image’s extension on that side.

For palletized images, the palette of the current image src is transparently copied to the newly created enlarged or shrunken image, so any color look-ups are performed on this palette.

Parameters:

left

The number of pixels the image should be enlarged on its left side. Negative values shrink the image on its left side.

top

The number of pixels the image should be enlarged on its top side. Negative values shrink the image on its top side.

right

The number of pixels the image should be enlarged on its right side. Negative values shrink the image on its right side.

bottom

The number of pixels, the image should be enlarged on its bottom side. Negative values shrink the image on its bottom side.

color

The color value to be used for filling the image. See #fill_background for more details.

options

Used to control color search process for palletized images. See #fill_background for more details.

If an optional block is provided, it will be passed the new image as an argument. The image will be automatically closed when the block completes.

Returns a new image on success or nil.



153
154
155
156
157
# File 'lib/free-image/modules/modify.rb', line 153

def enlarge_canvas(left, top, right, bottom, color, options = 0, &block)
  ptr = FreeImage.FreeImage_EnlargeCanvas(self, left, top, right, bottom, color, options)
  FreeImage.check_last_error
  self.class.new(ptr, &block)
end