: ImageMagick: distort perspective according to a vector path I want to use ImageMagick to transform a rectangular image (first page of a PDF, created using convert in.pdf[0] cover.png) to the following
I want to use ImageMagick to transform a rectangular image (first page of a PDF, created using convert in.pdf[0] cover.png) to the following white shape. I have the vector file and know about distorting in ImageMagick but have now clue which numbers to pass to the distort command. Can I somehow convert my path to the perspective parameters?
ImageMagick should be used to be able to automate the process easily.
More posts by @Nimeshi706
1 Comments
Sorted by latest first Latest Oldest Best
Yes. Take for example following images,
Images 1-2: Foreground and background
Then using following imagemagick shell script*:
convert ^
bg.png ^
-page +100+100 ^
( ^
fg.png ^
-matte ^
-virtual-pixel transparent ^
-distort Perspective ^
"0,0,20,105 206,0,157.5,60 0,264,130,303 206,264,302,235" ^
) ^
-layers flatten ^
out.png
you get:
* this is using Windows if you use a Mac or a Linux change ^ with note there can be no space after the end of line symbol.
How was this done?
How did i get the numbers. First you need 2 squares one original and one distorted. Measure the points of upper corner upper corner distorted and tack them together for a 4 number group (0,0,20,105). This is the first pair. Then measure the top right corner and the distorted top right corner (in same coordinate system). Do the same for lower left corner and lower right corner.
Image 3: Points of original and distorted one. Yellow line depicts extents of background image.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.