'ImageMagick : Compose with results of multiple convert

I want to create an image from to others, which are results of convert operations their self, without saving intermediate results to file system.

Long explanation:

I have two images, the two needs specific transformations :

  • avatar.jpg needs to be transformed to a rounded image -> rounded-avatar.jpg
  • background.jpg needs to have a color layer applied -> colored-background.jpg

Then I want to dissolve rounded-avatar.png in colored-background.jpg, so that I get something looking like this:

  +-----------+
  |     O     |
  +-----------+

What I have so far:

I know how to make those operations sequentially (maybe not the best way but that is not the subject of this question), I even made a working bash script :

#!/bin/bash

convert $1 -alpha set -background none -vignette 0x0 rounded-avatar.png

convert $2 -auto-orient -thumbnail 600x313^ -gravity center -extent 600x313 -region 100%x100% -fill "#256997" -colorize 72% colored-background.jpg

composite -dissolve 100 -gravity Center rounded-avatar.png colored-background.jpg -alpha Set $3

That I can call it with

$ ./myScript.sh avatar.jpg background.jpg output.jpg

What I want:

I want to avoid the saving of the two temporary images (rounded-avatar.jpg and colored-background.jpg) on the file system.

Why ?

  • This procedure has to be ran automatically on a web platform, I don't want to have to handle concurrency on those temp files with naming tricks.
  • The current script makes IM load the images two times in memory, it would probably be more efficient to reuse the computed images instead of writing them to disk and then load them in a new process.
  • Disk I/O are scarcity these days, let's save some.

I hope I am just missing the right keywords to find the answer in the documentation.

I am aware that this might seems over optimisation and I am not struggling with C10k issues here, but I just want to do this right (and understand IM syntax).



Solution 1:[1]

Mark's answer (I haven't looked tooooo closely at it) I trust to do "the right thing" for you.

Regarding...

"I just want to do this right (and understand IM syntax)."

...these two other SO answers may help you to understand the IM syntax better:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community