2
votes

I was wondering about ways to improve or shorten an ImageMagick conversion (I am rather new to ImageMagick myself).

What I have is a flat image (left in 1) and a 3d mock up that has transparent areas (right in 1, the dashed gets filled, blue and grey are solid ontop) that get filled with the transformed flat image.

I played around with several ImageMagick commands, and list them here for each step (no real numbers). What I am looking for is how to shorten/combine this sequence and the number of helper images created to get to the final image:

  1. My given input images. (Scroll down to 5. to see how these two should be combined to get my wanted output...)

  2. Crop the flash image and skew the two resulting parts (I noticed that the crop command spits you out the cropped result and overflow, so I use that to separate the sides of the flat image):

    # sequence for left side:
    convert base.png -crop WxH parts.png
    convert parts-0.png -virtual-pixel transparent -distort Perspective /
            '....' (-resize WxH) front-skewed.png
    
    #[... same for the right side ...]
    
  3. Combine the skewed parts:

    convert front-skewed.png side-skewed.png +append fill.png
    
  4. Combine the skewed fill and the mockup cover/mask, so that the fill gets inserted under the transparent parts of the cover.png (right image):

    composite fill.png cover.png -compose dst-atop -matte final.png
    
  5. Result after deleting the unwanted intermediary images.

illustration of my process steps

I will be running this from PHP via a exec, so any hint on how to do this more smoothly is welcome. I suppose I have to call each transformation as a seperate exec call, no?

This won't run excessively but only now and then when a new image gets added, so performance is not that much of a concern for me.

1
I do not quite understand: does this process chain already work for you? And you are looking for ways to optimize it? - Kurt Pfeifle
"I was wondering about ways to improve or shorten an ImageMagick conversion". It does work like this, but I am wondering how to make it better. - kontur
Your general algorithm is Ok and can't be improved much. But if you have working separate commands which you run sequentially, and since for you 'performance is not that much of a concern': there's not much else that could be improved. - Kurt Pfeifle

1 Answers

1
votes

In many cases you can put separate ImageMagick commands which are 'chained' (i.e. where a following command uses as input image the output image from a previous command) into one single command.

Since you do...

  • ...neither provide your input images separately (your [good!] illustration has it 'all-in-one'),
  • ...nor your exact separate IM commands,...

...I'm not inclined to construct my own example images and example commands to demonstrate and examplify this method.

I'll leave it at just pointing you to these resources: