Image conversion incomplete, grey results

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Image conversion incomplete, grey results

Post by wwftdg »

Converting some images via a cron task on our servers, but some of the images do not finish, end up with grey backgrounds. Usually, 2/10 images will not convert correctly. Any ideas whats the problem?

Image

code sample:

Code: Select all

convert $source -limit memory 1 -limit map 1 -thumbnail x800\> -bordercolor white -border 0 -gravity center -crop x800+0+0 +repage -strip -quality 90 -profile $rgbProfile $thumb

IM Version: ImageMagick 6.8.1-2 2012-12-24 Q16
Last edited by wwftdg on 2013-01-23T06:48:26-07:00, edited 1 time in total.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Image conversion incomplete, grey results

Post by magick »

Check your temporary disk space, are you running out of free space? You can change the temporary disk space path with MAGICK_TMPDIR environment variable or the -define registry:temporary-path=/data/tmp command line.
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

Will try, how do I set my own custom /tmp directory preference for ImageMagick?
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

Ok I updated the configure.xml file with the following items:

<configure name="MAGICK_TEMPORARY_PATH" value="/tmp"/>
<configure name="MAGICK_THREAD_LIMIT" value="1"/>
<configure name="MAGICK_MEMORY_LIMIT" value="1gb"/>
<configure name="MAGICK_DISK_LIMIT" value="10gb"/>

I restarted the apache server as well...is there anything else I need to do for these settings to take effect?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Image conversion incomplete, grey results

Post by magick »

Do you have policy.xml? Resource limits should be made in policy.xml. They have no effect in configure.xml. You can also set environment variables (e.g. MAGICK_TMPDIR=/data/tmp) or the command line (e.g. -limit memory 2MiB).
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

Right now there is only the configure file in that /usr/local/lib/ area

Do I just create one manually and IM will automatically read it?
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

Ok found the file in: /usr/local/etc/ImageMagick/policy.xml

I added these items to the document:

Code: Select all

<policy domain="resource" name="memory" value="3GB"/>
	<policy domain="resource" name="temporary-path" value="/tmp"/>
	<policy domain="resource" name="disk" value="5GB"/>
	<policy domain="resource" name="thread" value="1"/>
So I am going to restart the web server, on reboot will these settings go into effect? Also, is there any other options I should look at in order to fix this bug I am getting.
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

I have adjusted these values, even limiting the thread t 1 file, but still getting images ending in grey outputs...any ideas how to resolve?
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

So I was reading the imagemagick article about how to speed things up, as my error logs are showing IM has not finishing the completion of the images. It seems because we are sending so many to process sometimes, IM/Server gets overloaded. In the IM article it says to try using not so many system calls at once, so I am curious if anyone knows how to make our code more simple, minimize the system calls:

Code: Select all

$pWidth='';
$pHeight='';
system(binary_system_path()."convert $source -thumbnail X800\> -bordercolor '#ffffff' -border 0 -gravity center -crop X8000+0+0 +repage -strip -quality 100 -profile $rgbProfile $preview");

#check for MAX width
list($pWidth, $pHeight) = getimagesize($preview);
if ($pWidth > 500) {
	system(binary_system_path()."convert $preview -thumbnail '500X' -quality 100 $preview");
}
		
#check for MIN height
list($pWidth, $pHeight) = getimagesize($preview);
if ($pHeight < 300) {
	system(binary_system_path()."convert $preview -gravity center -background '#ffffff' -extent ".$pWidth."X300 -quality 100 $preview");
}
		
#Watermark
system(binary_system_path()."composite -quality 90 -gravity center $watermark $preview $preview");
wwftdg
Posts: 10
Joined: 2013-01-10T08:40:49-07:00
Authentication code: 6789

Re: Image conversion incomplete, grey results

Post by wwftdg »

And the main error in our logs for IM that causes the incomplete images starts with this:

convert: Premature end of JPEG file
Post Reply