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:
My given input images. (Scroll down to 5. to see how these two should be combined to get my wanted output...)
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 ...]
Combine the skewed parts:
convert front-skewed.png side-skewed.png +append fill.png
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
Result after deleting the unwanted intermediary images.
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.