Search code examples
bashimagemagick-convert

Can you help me get rid of an intermediary output in my imagemagick convert commands?


I have the following convert command in bash.

    convert "$WALLPAPER1" -resize "${H[0]}"x"${V[0]}"^ -gravity center -crop "${H[0]}"x"${V[0]}"+0+0 "$WALLPAPERS/.temp1.jpg"
    convert "$WALLPAPER2" -resize "${H[1]}"x"${V[1]}"^ -gravity center -crop "${H[1]}"x"${V[1]}"+0+0 jpg:- |
    convert "$WALLPAPERS/.temp1.jpg" - +append "$WALLPAPERS/.temp.jpg"

Is there a way I can get rid of the "$WALLPAPERS/.temp1.jpg" intermediary? So is there a way to carry over the output of the first convert over to the input of the third convert?


Solution

  • convert "$WALLPAPER1" -resize "${H[0]}"x"${V[0]}"^ -gravity center -crop "${H[0]}"x"${V[0]}"+0+0 -write mpr:temp1 +delete \
    "$WALLPAPER2" -resize "${H[1]}"x"${V[1]}"^ -gravity center -crop "${H[1]}"x"${V[1]}"+0+0 -write mpr:temp2 +delete \
    -gravity north mpr:temp1 mpr:temp2 +append "$WALLPAPERS/.temp.jpg"
    

    There was no need to have 3 convert calls. Instead of writing to file you can write to memory-program-register (mpr) and then recall later. The +delete deletes the original image.