Page 1 of 1

Perspective distort and losing part of the image

Posted: 2007-11-06T12:54:42-07:00
by Bonzo
As I read it with the perspective distort ( and other distort methods ) if part of the image is outside the original it is lost.

I am trying to make a "cube" and I can get the 2 sides with shear OK but I am using perspective distort for the top and it is not working.
Is there a way around this ? I wonder if I should shear it first then distort it ?

Code: Select all

<?php
// Distort the images to use
exec("convert src.jpg -background none -shear 0x20 shear_y1.png ");
exec("convert src.jpg -background none -shear 0x160 shear_y2.png ");
exec("convert -background none -gravity Center shear_y1.png shear_y2.png +append output_shear.png"); 
exec("convert src.jpg -matte -background none -virtual-pixel background -distort Perspective '0,0 0,239, 319,239, 319,0, 0,0 300,100, 600,0, 300,-100' -trim car4.png");
// Join the first 2 images along the longest edge
exec("convert -background none -gravity Center shear_y1.png shear_y2.png +append output_shear.png"); 
// Composite the top image
exec("convert -size 700x700 xc:none output_shear.png -gravity center -composite car4.png -geometry -140-115 -composite -trim output_shear1.png");
?>
Image

Re: Perspective distort and losing part of the image

Posted: 2007-11-15T22:55:56-07:00
by anthony
Use +distort, and the output image will be adjusted to contain the whole of the source image (if posible) with an appropriate virtual canvas offset.
That later part allows you to determine exactly the actual position of the output image, without lossing any image data. You can use things like '-layers merge' to merge images with different offsets together correctly, again without lossing any actual image data.

An example of this is planned, but I have been side tracked by other lower level improvements so have not created it yet.

Re: Perspective distort and losing part of the image

Posted: 2007-11-16T12:54:05-07:00
by Bonzo
That worked thanks Anthony.

Image