Page 1 of 1
Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T02:29:46-07:00
by agriz
Hi
It seems scripts are using high resource.
I got warning from my vps hosting.
The scripts are very simple convert script.
exec("convert .....");
Is there anything should i do after the convert like closing imagemagick or something?
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T05:34:17-07:00
by magick
Add resource limits to your command line. For example, to trade memory usage for disk I/O, add '-limit memory 2mb'.
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T05:39:59-07:00
by agriz
Is there any other better way to do it?
convert 1.png image1.jpg -geometry +0+0 -compose DstOver -composite image2.jpg -geometry +100+25 -compose DstOver -composite image3.jpg -geometry +227+28 -compose DstOver -composite output.jpg
1.png has some transparent area where those three jpgs are added.
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T05:45:42-07:00
by magick
To reduce resource requirements you must trade off memory for disk I/O or impose a CPU throttle (periodically yield the CPU for at least the time specified in milliseconds, see
https://www.imagemagick.org/script/reso ... nvironment). The alternatives are to use some other program to do your work or get a different host that is less restrictive about CPU and memory resources.
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T06:14:28-07:00
by agriz
But using imagemagick, is this the best method to do the work?
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T06:19:02-07:00
by agriz
The link is helpful.
Can you give me how to use "MAGICK_THROTTLE" in PHP.
I am using imagemagick with exec command
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T10:31:42-07:00
by magick
You can set all resources from the command line. See
http://www.imagemagick.org/script/comma ... .php#limit.
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-17T22:44:11-07:00
by anthony
The command you gave is probably about the best. You need at least enough memory to hold the source and destination images. that is about as small as you can get.
The MagickCore CompositeImages() function actually directly merged source into destination without cloning a new image. There is an exception to this for the image mapping and Variable Blur Mapping compositions, which require random access to the destination image, but generally, only memory to hold only the input images is needed.
The CLI interface automatically deletes the 'source' or 'overlay' image as soon as the composition can finished modifying the destination image.
The only other solution for a smaller memory footprint would be some type of image streaming composition method.
The PbmPlus (also knows as NetPbm) may be able to do this, as that image processing library is designed with image streaming in mind. HOWEVER
- the manual never mentions if a particular command deals with images 'in total' (that is reading in the whole image first - like IM does) or as a line-by-line buffered process
- images are only dealt with as raw image data, without any meta data
If you know of a image streaming (row-by-row) composition (or just overlay) command, PLEASE let us know. Such a command would solve a number of other problems with processing 'massive images' with 'minimum memory' and 'high efficiency'.
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-18T12:07:54-07:00
by agriz
"If you know of a image streaming (row-by-row) composition (or just overlay) command"
No. I don't know that.
Legends are here. How do i know?
Re: Imagemagick and resource usage - Optimize?
Posted: 2011-11-18T12:44:30-07:00
by magick
If you haven't already read it, see
http://www.imagemagick.org/script/architecture.php concerning the ImageMagick architecture. Learn why we choose the more robust but slower method for processing images. Image processing is a complex field, compromises were made to support the widest variety of image processing algorithms and image formats.