Yes. Take for example following images,
Images 1-2: Foreground and background
Then using following imagemagick shell script*:
-page +100+100 ^
-virtual-pixel transparent ^
-distort Perspective ^
"0,0,20,105 206,0,157.5,60 0,264,130,303 206,264,302,235" ^
-layers flatten ^
* this is using Windows if you use a Mac or a Linux change
\ 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.