Page 1 of 1

PHP Imagick Distortion Perspective

Posted: 2013-12-05T01:02:47-07:00
by nisse
I'm creating a webshop where the client can change the size and shape of the logotype.

There's an option with perspective images that doesn't work the way I want.

As seen in this image: http://imagebin.org/280577 - the red dot on the bottom left corner is negative towards the upper left dot. This makes the entire image go bananas.

As to compare with this: http://imagebin.org/280576 - where the red dot on the bottom left corner is positive towards the red dot on the upper left corner.

The coordinates for the first image is: $area = "232,327;406,350;178,380;385,455"

sscanf ( $area, "%d,%d;%d,%d;%d,%d;%d,%d", $tlx, $tly, $trx, $try, $blx, $bly, $brx, $bry );

$points = array (0, 0, 0, 0, # top left

$logoback->getImageWidth (), 0,
$trx - $tlx, $try - $tly, # top right

0, $logoback->getImageHeight (),
$blx - $tlx, $bly - $tly, # bottom right

$logoback->getImageWidth (),
$logoback->getImageHeight (),
$brx - $tlx,
$bry - $tly );# bottom left
And the control points I get is: array( (int) 0 => (int) 0, (int) 1 => (int) 0, (int) 2 => (int) 0, (int) 3 => (int) 0, (int) 4 => (int) 175, (int) 5 => (int) 0, (int) 6 => (int) 174, (int) 7 => (int) 23, (int) 8 => (int) 0, (int) 9 => (int) 75, (int) 10 => (int) -54, (int) 11 => (int) 53, (int) 12 => (int) 175, (int) 13 => (int) 75, (int) 14 => (int) 153, (int) 15 => (int) 128 )

$logoback->distortImage ( Imagick::DISTORTION_PERSPECTIVE, $points, TRUE );

I think it's the array key 10 (-54) that's screwing things up.

Basically the problem is that the image doesn't follow the line when the left bottom red dot is left of the top left red dot.

Re: PHP Imagick Distortion Perspective

Posted: 2013-12-05T11:41:52-07:00
by fmw42
I do not use Imagick, because it is not supported much any longer. Also, it was not created by the ImageMagick developers.

But if you can give me a better idea of what you are trying to do, I can probably give you a command line equivalent.

I am not really following what the issue is. The warp results will depend upon your control points. If they are not chosen properly, you will not get expected results.

But, please provide a picture of the input image, what points are the input 4 coordinates and what points are the output 4 coordinates. Also provide your output result. You can mark the control points on the input image and I can extract them.

Do you want to warp the whole image or just warp the one area and crop to that?

What version of Imagemagick are you using and what version of Imagick?