Page 1 of 1

Imagick with PHP Memcache

Posted: 2012-05-15T02:50:48-07:00
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

Re: Imagick with PHP Memcache

Posted: 2012-05-22T08:07:17-07:00
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 ?!?

Re: Imagick with PHP Memcache

Posted: 2012-05-22T09:17:43-07:00
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.