PHP Imagick Distortion Perspective
Posted: 2013-12-05T01:02:47-07:00
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.
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.