Imagemagick and resource usage - Optimize?

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
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Imagemagick and resource usage - Optimize?

Post 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?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick and resource usage - Optimize?

Post by magick »

Add resource limits to your command line. For example, to trade memory usage for disk I/O, add '-limit memory 2mb'.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Imagemagick and resource usage - Optimize?

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick and resource usage - Optimize?

Post 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.
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Imagemagick and resource usage - Optimize?

Post by agriz »

But using imagemagick, is this the best method to do the work?
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Imagemagick and resource usage - Optimize?

Post by agriz »

The link is helpful.

Can you give me how to use "MAGICK_THROTTLE" in PHP.
I am using imagemagick with exec command
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick and resource usage - Optimize?

Post by magick »

You can set all resources from the command line. See http://www.imagemagick.org/script/comma ... .php#limit.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Imagemagick and resource usage - Optimize?

Post 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'.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
agriz
Posts: 237
Joined: 2011-10-01T02:21:30-07:00
Authentication code: 8675308

Re: Imagemagick and resource usage - Optimize?

Post 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? :)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Imagemagick and resource usage - Optimize?

Post 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.
Post Reply