PHPKonf: Istanbul PHP Conference 2017


(PECL imagick 2.0.1)

Imagick::distortImageDistorts an image using various distortion methods


bool Imagick::distortImage ( int $method , array $arguments , bool $bestfit )

Distorts an image using various distortion methods, by mapping color lookups of the source image to a new destination image usually of the same size as the source image, unless 'bestfit' is set to TRUE.

If 'bestfit' is enabled, and distortion allows it, the destination image is adjusted to ensure the whole source 'image' will just fit within the final destination image, which will be sized and offset accordingly. Also in many cases the virtual offset of the source image will be taken into account in the mapping.

This method is available if Imagick has been compiled against ImageMagick version 6.3.6 or newer.



The method of image distortion. See distortion constants


The arguments for this distortion method


Attempt to resize destination to fit distorted source

Return Values

Returns TRUE on success.


Throws ImagickException on error.


Example #1 Using Imagick::distortImage():

Distort an image and display to the browser.

/* Create new object */
$im = new Imagick();

/* Create new checkerboard pattern */

/* Set the image format to png */

/* Fill new visible areas with transparent */

/* Activate matte */

/* Control points for the distortion */
$controlPoints = array( 1010

10$im->getImageHeight() - 20,
10$im->getImageHeight() - 5,

$im->getImageWidth() - 1010,
$im->getImageWidth() - 1020,

$im->getImageWidth() - 10$im->getImageHeight() - 10,
$im->getImageWidth() - 10$im->getImageHeight() - 30);

/* Perform the distortion */                       

/* Ouput the image */
header("Content-Type: image/png");

The above example will output something similar to:

Output of example : Using Imagick::distortImage()

See Also

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top