image composition with convert and mpc files

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
phil404

image composition with convert and mpc files

Post by phil404 »

Hello everyone,

i am facing the task of rendering a png file for customizable avatar animations to be used in flash. To be more specific, i have up to 80 "frames" with offsets +0+0, +65+0,+130+0,.... Each "frame" has up to 8 png images stacked on its offset position. so far i solved it by using the following command.

Code: Select all

/usr/bin/convert -size 195x65 -page 195x65 -quality 95 -compress ZIP 
-page +0+0  /srv/www/htdocs/resources/img/avatar/layer/03/03/11/000/030311000_0038.png 
-page +0+0  /srv/www/htdocs/resources/img/avatar/layer/03/01/10/004/030110004_0038.png 
-page +0+0  /srv/www/htdocs/resources/img/avatar/layer/03/01/09/004/030109004_0038.png 
-page +65+0 /srv/www/htdocs/resources/img/avatar/layer/03/01/01/000/030101000_0039.png 
-page +65+0 /srv/www/htdocs/resources/img/avatar/layer/03/03/11/000/030311000_0039.png 
-page +65+0 /srv/www/htdocs/resources/img/avatar/layer/03/01/10/004/030110004_0039.png 
-page +130+0 /srv/www/htdocs/resources/img/avatar/layer/03/01/01/000/030101000_0040.png 
-page +130+0 /srv/www/htdocs/resources/img/avatar/layer/03/03/11/000/030311000_0040.png 
-page +130+0 /srv/www/htdocs/resources/img/avatar/layer/03/01/10/004/030110004_0040.png 
-background none -flatten /srv/www/htdocs/cache/img/avatar/1-3-17-29-38-85-122-85/03.png
Right now i'm trying to optimize the process since it will be called a lot and every bit of cpu time saved will be worth it :)

One attempt was to generate .mpc files in advance for each source png. however when running the same command with .mpc files instead of .png it seems that the page offsets are ingored. All pngs are stacked at offset +0+0. As i learned from the manual the mpc should behave the same as the original png. Is there anything that i am missing or is offset not supported for .mpc format?

Any other input on how to solve the task best would be really appreciated. i spent quite some time trying other solutions but the above command was the only one that really worked.

Thanks a lot in advance for any help and hints.

regards,

phil
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: image composition with convert and mpc files

Post by magick »

MPC and MIFF should support *all* image properties whereas other image formats may only support a subset of the properties. Convert your PNG to MPC. Look at the resulting MPC file. Is there a property that starts with 'page='? Also make sure you are using a modern version of ImageMagick.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: image composition with convert and mpc files

Post by el_supremo »

I notice that you're using a quality of 95 with a PNG file. Since the PNG compression is lossless you can trade off the final file size against the cpu time. For example, a quality of 25 will produce a larger output file but will take less CPU time to do it. I don't know if that will produce a significant reduction of CPU time for an acceptable filesize in your situation. You'll have to play with it.
See: http://imagemagick.org/script/command-l ... hp#quality

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image composition with convert and mpc files

Post by anthony »

Note 'MPC' file format is actually two related files with different suffix'es.

this can be important for later clean up. By MPC is practically instant read as it does not have to be decoded, and as it was usually just written to disk it is often in the disk cache making the access even faster and immediate.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
phil404

Re: image composition with convert and mpc files

Post by phil404 »

Firstly, thanks a lot for the quick help.

@magick: Indeed, the mpc meta file had the page property. I'm using ImageMagick 6.4.0 06/07/08 Q16 on a suse linux box. Forgot to mention in my initial post.

What i discovered was that the page offsets for the mpc's were working fine and the layers were not stacked all at +0+0, which was hard to see...

It turned out that the output file would only have the dimensions 65x65 and the layers were positioned out side the canvas. I used the same command and parameters as of my initial post, except using .mpc instead of .png. The only way i could solve it was to use additional, blank .png with the dimensions the output file should have.

So, problem kind of solved :)

Unfortunately the persistent memory did not have the result i hoped for. the performance gain is marginal. I guess it really improves things when working with huge files. The source files i use are averaging at around 3KB. Getting rid of the compression did not have any markable results also. I guess there's no way to improve things, keeping in mind that i have at top 408 png's to be merged.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: image composition with convert and mpc files

Post by anthony »

Better solutions...

1/ use -repage WxH to set final canvas size before -flatten

2/ use -mosaic which starts with the initial canvas size but then expands the right and bottom boundaries (0,0 remains fixed)

3/ use -layers merge wich ignores all canvas size information, and merges all layers into a new layer (with appropriate offset) of the smallest size need to hold all layer images. None of the images are clipped, and each side will be touching at least one of the layer images given. You could just that posibly negative offset with +repage
afterward if not wanted.

Best idea is -background none -layers merge +repage

See IM Examples, Layers
http://www.imagemagick.org/Usage/layers/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply