問題描述
使用 ImageMagick 改進從平面圖像到 3d 模型的轉換鏈 (Improve this conversion chain from flat images to 3d mockup with ImageMagick)
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.
參考解法
方法 1:
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:
- Working with ordered lists of images
- 'Cloning' or 'duplicating' images inside an ordered list of images
- Parenthesis -- processing images 'on the side'
- Sequencing image operations
- Debugging complex operation sequences
(by kontur、Kurt Pfeifle)