Page 1 of 1

Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-04T08:14:42-07:00
by zfmobil
Hello,

thanks for reading this, I need some help: I wrote a PHP-script that generates animated GIFs from a range of JPGs. The script worked fine until my provider updated ImageMagick and applied some security patches to the server.

Now the PHP-script doesn't finish its work anymore. Although I am able to setup the Imagick-Object (the GIF) with all frames needed (about 32), the "WriteImages"-funtion fails as soon as I have more than six JPGs added to the animated GIF. The JPGs are sized 300x400 Pixel.

Since I need the script, I tried to generate the GIF without the PHP-class but with exec(). Same issue there, probably the class uses exec() internally?

However, my provider (ALFAHOSTING) said that this is either an error of Imagick or the "system", so they cannot do anything about it. This is really annyoing for me, I am working a lot with animated GIFs.

I wonder if anyone has an idea of what is going wrong and what else I could try?

Below is the script I used for testing and this is the address where it is hosted: http://makerlove.zfmobil.de/_te/width300/test_exec.php

Thanks a lot! Martin.

Code: Select all

<?php 
echo "<pre>"; 

phpinfo(INFO_GENERAL);

echo "<br>";
echo "<br>";



//system("type convert");  
echo "IMAGICK VERSION:<br>";
exec("/usr/bin/convert -version 2>&1",$output,$return_value);  
var_dump($output);
echo "----------------------------------------<br><br>";



array_map('unlink', glob("*.gif")); // delete all GIFs in the folder


// Try to create animated GIFS with exec
$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg -loop 0 animation1.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg -loop 0 animation1.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg -loop 0 animation2.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg -loop 0 animation2.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg -loop 0 animation3.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg -loop 0 animation3.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg -loop 0 animation4.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg -loop 0 animation4.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg -loop 0 animation5.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg -loop 0 animation5.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg 005.jpg -loop 0 animation6.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg 005.jpg -loop 0 animation6.gif 2>&1",$output,$return_value);
var_dump($output);

$output = "";
echo "<br>exec /usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg 005.jpg 006.jpg -loop 0 animation7.gif RESULT:<br>";
exec("/usr/bin/convert -delay 1x1 000.jpg 001.jpg 002.jpg 003.jpg 004.jpg 005.jpg 006.jpg -loop 0 animation7.gif 2>&1",$output,$return_value);
var_dump($output);


echo "<br>";
echo "<br>";
// Try to create animated GIFS with exec

$GIF = new Imagick();
$GIF->setFormat("gif");

$frame = new Imagick();
for($i=0;$i<7;$i++)
{
	$fileJPG = sprintf('%03d',$i).".jpg";
	$frame->readImage($fileJPG);
    $frame->setImageDelay(20);
    $GIF->addImage($frame);
	$frame->destroy();	
}

$GIF->writeImages("output.gif",true);

echo "</pre>"; 


/*exec("/usr/bin/convert -delay 1x1 000.jpg -delay 1x6 001.jpg 002.jpg 003.jpg 004.jpg 005.jpg 006.jpg -delay 1x1 007.jpg -delay 1x6 008.jpg 009.jpg 010.jpg 011.jpg 012.jpg 013.jpg 014.jpg -delay 1x1 015.jpg -delay 1x6 014.jpg 013.jpg 012.jpg 011.jpg 010.jpg 009.jpg 008.jpg -delay 1x1 007.jpg -delay 1x6 006.jpg 005.jpg 004.jpg 003.jpg 002.jpg 001.jpg -loop 0 animation.gif");
*/


?>

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-04T09:05:48-07:00
by fmw42
Check with your ISP to see if they put the new Imagemagick in some other location besides /usr/bin/convert. Perhaps /usr/local/bin/convert? Also find out what the new version number is.

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-04T09:08:41-07:00
by snibgo
From your linked page:
convert: memory allocation failed `animation7.gif'
This means IM asked the system for more memory, and the system said "no".

How many pixels do your images have?

Q8 will use half the memory of Q16.

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-04T14:55:38-07:00
by zfmobil
Hello and thanks a lot for you replies.

I can't believe it's a memory issue. All images together are less than 1MB and the resulting GIF would be maybe 5MB or so. Nevertheless, is there any other exec() prog I could use to test how much memory can be grabbed?

First thing my script does is reporting the Imagick version:

Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-09-23 http://www.imagemagick.org

Since I cannot change the servers version to Q8, I have to live with Q16. The images used are, as said 300x400 Pixel in size, like this:

Image

@fmw42: Thanks for this suggestion, I'll ask my ISP.

Thanks a lot. Still no solution, but I will post here what happens furthermore.

Martin

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-04T15:58:31-07:00
by fmw42
Your command is not using Imagick. It is just using PHP exec() and calling an IM command. What did your ISP change? Was it Imagick or Imagemagick or both.

What do you get from:

Code: Select all

<?php
echo "<pre>";
system("type -a convert");  
echo "</pre>";
?> 
It should tell you where IM convert resides.

What do you get from:

Code: Select all

<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
and from

Code: Select all

<?php
exec("/usr/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-06T06:15:50-07:00
by zfmobil
Hello and thanks a lot for your efforts.

Actually my script used both the exec() and the PHP-version (have a look at the end of it for PHP).

However, now my ISPs support technicians started a deeper research of the problem and found out , that the memory was set to low for Imagick - as stated by the error message. So they adjusted it to 128MB and as a result the scripts run as they did all the time before.

So, thanks a lot for your suggestions, I really appreciate this very much!

However, even if OT here, could you please explain whats the difference between Imagick, Imagemagick and MagickWand? I tried to find out, but found no clear desicription of what is what. I thought there is Imagick and the PHP class, that is using it?

Thanks!

Martin

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-06T07:30:10-07:00
by snibgo
Glad you've solved it.

ImageMagick is the name of a product, a bunch of software. I often abbreviate this to IM. IM is the focus of these forums.

MagickWand and MagickCore are two C-language interfaces (ie collections of functions, data structures etc) to IM. Roughly speaking, MagickWand is the higher level interface, MagickCore is the lower level.

IMagick is the name of a separate product that sits on top of IM, providing a different interface. Different people wrote and maintain IMagick. For people's convenience, a forum here is dedicated to IMagick, and may be useful for sharing experience and asking questions. As far as I know, the IMagick people don't respond to bug reports made here.

Re: Please help: Memory allocation error with Magick PHP and exec()

Posted: 2016-10-06T12:49:33-07:00
by zfmobil
Thanks a lot, girls and guys and all the others here!