Page 1 of 1

Problems with bilinear distortion

Posted: 2015-10-12T13:57:13-07:00
by eriqjaffe
I'm running into some issues with bilinear distortion corrupting an image. The image is being created on an HTML5 canvas that I'm posting to a PHP script. The expected result should look like this:

Image

...but my production server is giving me this:

Image

The code that works on my development system is as follows:

Code: Select all

header('Content-type: image/png');
header('Content-Disposition: attachment; filename="test.png"');

$deformation = $_POST['deform'];
$amount = $_POST['amount'];
$encoded = $_POST['imgdata'];
$encoded = str_replace(' ', '+', $encoded);
$decoded = base64_decode($encoded);

echo $deformation($decoded,40);

function skewUp($image,$amount) {
	$im = new Imagick();
	$im->setBackgroundColor(new ImagickPixel('transparent'));
	$im->readimageblob($image);
	$im->setImageVirtualPixelMethod( imagick::VIRTUALPIXELMETHOD_BACKGROUND );
	$im->trimImage(0);
	$im->setImagePage(0, 0, 0, 0);
	$x1 = $im->getImageWidth();
	$x2 = $im->getImageWidth();
	$y1 = $im->getImageHeight();
	$y2 = $im->getImageHeight()/((100-$amount)*0.01);
	$im->setGravity(imagick::GRAVITY_NORTH);
	$im->extentImage ($x2,$y2,0,0);
	$points = array(
		0, 0, 0, $im->getImageHeight()-$y1, #top left
		0, $y1, 0, $y2, #bottom left
		$x1, 0, $x1, 0, #top right
		$x1, $y1, $x1, $y1 #bottom right
	);

	$im->distortImage( Imagick::DISTORTION_BILINEAR, $points, TRUE );
	$im->trimImage(0);
	$im->setImagePage(0, 0, 0, 0);
	return($im);	
}
One thing that could be the cause is that my development box is not an exact mirror of my production server - the dev server is running PHP 5.5.9 with imagick 6.7.7-10 while the production server is running PHP 5.4.43 with imagick 6.5.4-7. Maybe there's just something I need to do differently on the production box, but I can't figure out what. Any assistance would be appreciated.