note 81819 added to function.imagick-clippathimage
| From: | ColemanNitroy at osu1 dot php dot net | Date: | Fri, 14 Mar 2008 13:15:01 +0000 |
| Subject: | note 81819 added to function.imagick-clippathimage | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-137059@lists.php.net to get a copy of this message | ||
I found Imagick::clipPathImage and Imagic::clipImage did not work as I had expected. I thought they
would just clip the path and throw away the extra data and you are done. Not the case.
Here is how I was able to use a clipping path:
<?php
$img = new Imagick("/Path/To/Test/Image.psd");
$geometry = $img->getImageGeometry();
// Uses the first path as the clipping path
$img->clipPathImage("#1", false);
// Fill the clipped part with a color
$draw = new ImagickDraw();
$draw->setFillColor("#000000");
$draw->color(0,0, imagick::PAINT_RESET);
$img->drawImage($draw);
// Composite the clipped image with the old image. Set the color of the composite to any color
you want to be the outside part.
$composite = new Imagick($path);
$composite->newImage( $geometry['width'], $geometry['height'], new
ImagickPixel("white"), 'png');
$composite->compositeImage($img, imagick::COMPOSITE_COPY, 0, 0);
?>
Then doing any resizing or creating thumbnails from the resulting image disregarded all the
previous commands so I "saved" it and started with a new Imagick object
<?php
// Copy the image so clip is "saved"
$clipped = new Imagick();
$clipped->readImageBlob($composite->getImageBlob());
?>
I'm sure there is a simpler way, but this took me awhile to get right and there were some
hurdles to cross so I hope it is able to help someone on the way.
This is all the convert equivalent of:
$ convert Test.psd -fill white -colorspace rgb -draw "color 0 0 reset" -clip -colorspace
rgb -draw "Image Copy 0,0 0,0 'Test.psd'" OutputFile.png
----
Server IP: 209.41.74.194
Probable Submitter: 12.15.136.26
----
Manual Page -- http://www.php.net/manual/en/function.imagick-clippathimage.php
Edit -- https://master.php.net/note/edit/81819
Del: integrated -- https://master.php.net/note/delete/81819/integrated
Del: useless -- https://master.php.net/note/delete/81819/useless
Del: bad code -- https://master.php.net/note/delete/81819/bad+code
Del: spam -- https://master.php.net/note/delete/81819/spam
Del: non-english -- https://master.php.net/note/delete/81819/non-english
Del: in docs -- https://master.php.net/note/delete/81819/in+docs
Del: other reasons-- https://master.php.net/note/delete/81819
Reject -- https://master.php.net/note/reject/81819
Search -- https://master.php.net/manage/user-notes.php