Imagick with PHP Memcache

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
jaslee
Posts: 11
Joined: 2010-02-25T06:03:36-07:00
Authentication code: 8675308

Imagick with PHP Memcache

Post by jaslee »

Hi,
I have an "on-the-fly" image process which performs alpha compositing of an alpha-transparent image to a colour-filled image. The colour-filled image is static whereas the alpha-transparent images are dynamically called - and there are a lot of them.

I use the $img->compositeImage() and currently fetch all images from disk. However, because the colour-filled image is being used all the time, I am thinking it would be more efficient to hold that image in memory using Memcache rather than reading from disk. I hope that makes sense to do.

I am using Memcache for the first time and I am successful in reading an image and making it persist in memory ($memcache->get("my_image")). However, when I fetch the image and try to use compositeImage(), I get :-

"Fatal error: Call to a member function compositeImage() on a non-object"

My code snippet looks like this :-

$img = new Imagick();
$img = $memcache->get("my_image");
$img->compositeImage( new Imagick(...), imagick::COMPOSITE_COPYOPACITY, 0, 0 );

Is this the correct way for instantiating a new imagick object and assigning it the the image fetched from Memcahce??

Any help of advice much appreciated.

Jason
jaslee
Posts: 11
Joined: 2010-02-25T06:03:36-07:00
Authentication code: 8675308

Re: Imagick with PHP Memcache

Post by jaslee »

No suggestions or advice?

I was testing various scenarios :-

Scenario 1
Non-Memcached image with compositeImage() i.e. current implementation --> works

Code: Select all

$img1 = new Imagick('pink.png');
$img1->compositeImage( new Imagick('http://'.$my_dynamic_image.'.png'), imagick::COMPOSITE_COPYOPACITY, 0, 0 );

header('content-type: image/png');
echo $img1;
Scenario 2
Assigning Memcached image to Imagick object --> works - but just get a pink image with no alpha

Code: Select all

$img1 = new Imagick();
$img2 = $memcache->get("my_pink_image");
$img1 = $img2;

header('content-type: image/png');
echo $img1;
Scenario 3
Assigning Memcached image to Imagick object AND using compositeImage() --> Error (see below)

Code: Select all

$img1 = new Imagick('pink.png');
$img2 = $memcache->get("my_image");
$img1 = $img2;

$img1->compositeImage( new Imagick('http://'.$my_dynamic_image.'.png'), imagick::COMPOSITE_COPYOPACITY, 0, 0 );

header('content-type: image/png');
echo $img1;
Error message I get is :
Fatal error: Call to a member function compositeImage() on a non-object in myscript.php on line...
...I would have thought that if Scenario 1 works and Scenario 2 works, then follows that Scenario 3 should work ?!?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagick with PHP Memcache

Post by magick »

To investigate, we need a complete minimal working example that illustrates the problem. We need to reproduce the problem before we can comment further.
Post Reply