HomeImagickImagickDrawImagickPixelImagick Pixel IteratorImagick KernelTutorial Source codeReport an issue

Image geometry reset

← screenEmbed   retro →
After calling trimImage it leaves the image in a crop mode where the geometry of the canvas is
different from that of the actual image.

When you call another function that uses the images geometry, it will be applied to the 'wrong'
geometry, that of the uncropped image. e.g. When you are calling distortImage with
Imagick::DISTORTION_ARC to produce an arc of text, this produces the unwanted effect of the
text going off the image.

The way to fix this is to reset the geometry for the image through the Imagick function setImagePage
which is called repage in the Image Magick manual.
function imageGeometryReset()
    $draw = new \ImagickDraw();


    $textOnly = new \Imagick();
    $textOnly->newImage(600, 300, "rgb(230, 230, 230)");
    $textOnly->annotateImage($draw, 30, 40, 0, 'Your Text Here');
    $textOnly->setImagePage($textOnly->getimageWidth(), $textOnly->getimageheight(), 0, 0);

    $distort = array(180);

    $textOnly->distortImage(Imagick::DISTORTION_ARC, $distort, false);


    header("Content-Type: image/png");
    echo $textOnly->getimageblob();