Question

Would it be possible somehow to pass image resource to Imagick class on initialization instead of passing the file name? For example:

$imageResource = imagecreatefromjpeg('test.jpg');
$imagegickObj = new Imagick($imageResource);

Because I have a class that manipulates images with GD library. And I need some functionality from Imagick class as well. So it would be great that the image once opened could be passed as a resource even to Imagagick class on init.

Your help would be appreciated.

Was it helpful?

Solution

Short version, no. The resource is just the underlying program data structure that GD uses to store the image while it is memory. There is no way to pass this directly to Imagick to have it open it as an image.

Theoretically you could output it is as a PNG using the imagepng() function, capture it with an output buffer, and then feed it to Imagick, however this would be a bit silly. You'd almost certainly be better off by just writing it to a temp PNG* file and then re-reading it. Or converting your current library to use Imagick everywhere.

*Don't use JPEG for this - you will lose image quality as it is a lossy format.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top