note 111332 added to imagick.trimimage

From: Date: Fri, 08 Feb 2013 11:17:52 +0000
Subject: note 111332 added to imagick.trimimage
Groups: php.notes 
Request: Send a blank email to php-notes+get-193555@lists.php.net to get a copy of this message
The command for trim can return info which tells you the coordinates of where the image was cropped and the new dimensions of the trimmed image. I couldn't find an example for how to do that with this class, so here's how I did it: <?php // Create and trim image $image = new Imagick('image.png'); $image->trimImage(0.3); /** * Imagick:: getImagePage() gives us an array with the width, height, x and y coordinates of the trimmed image * However, the width and height are of the original image */ $imagePage = $image->getImagePage(); list($x, $y) = array($imagePage['x'], $imagePage['y']); // So we need to reset the image page to get the right height and width of the trimmed image $image->setImagePage(0, 0, 0, 0); list($width, $height) = array($image->width, $image->height); ?> This will leave you with two variables for the width and height of the trimmed image, plus two variables for the x-coordinate and y-coordinate of the trimmed area relative to the original image. This information is useful when the image you're trimming is the difference between two images (e.g. from Imagick::compareImages(), and you want to crop the original image to the same size and position as the difference. ---- Server IP: 69.147.83.199 Probable Submitter: 90.198.28.93 ---- Manual Page -- http://php.net/manual/en/imagick.trimimage.php Edit -- https://master.php.net/note/edit/111332 Del: integrated -- https://master.php.net/note/delete/111332/integrated Del: useless -- https://master.php.net/note/delete/111332/useless Del: bad code -- https://master.php.net/note/delete/111332/bad+code Del: spam -- https://master.php.net/note/delete/111332/spam Del: non-english -- https://master.php.net/note/delete/111332/non-english Del: in docs -- https://master.php.net/note/delete/111332/in+docs Del: other reasons-- https://master.php.net/note/delete/111332 Reject -- https://master.php.net/note/reject/111332 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#193555) next »