possible bug in distortImage for barrelinverse

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

possible bug in distortImage for barrelinverse

Post by fmw42 »

I am by no means an expert at Imagick, but I believe that I have uncovered a bug, if I am not making a mistake.

The result using Imagick is not symmetric as it should be and tends to bend more upward than downward.

Here is the input image:

Image

Here is the Imagick code:

Code: Select all

<?php

// Timer function
function microtime_float()
{
    list($utime, $time) = explode(" ", microtime());
    return ((float)$utime + (float)$time);
}


echo "PHP Loop Imagick<br>";	

// Input image name if used
$image = "testoutline1.png";

// Output image name
$output = "testbulge1_imagick.png";

// How many time to run
$run = "1";

// Setup default cycle time
$time = "";

// Start timer
$script_start = microtime_float();

// Loop through the code
For ( $i=1; $i <= $run; $i++ ){

try
{

$im = new Imagick();

$im->readImage( $image );

$im->setImageVirtualPixelMethod( Imagick::VIRTUALPIXELMETHOD_WHITE );

$im->setGravity( Imagick::GRAVITY_CENTER );

$im->setBackgroundColor( "white" );

$im->extentImage( 935, 169, 0, 0 );

$distortion = array( 0, 0, 0, 1, 0, 0, -0.1, 1.1 );

$im->distortImage( Imagick::DISTORTION_BARRELINVERSE, $distortion, false );

$im->trimImage(0);

$bordercolor = new ImagickPixel( "white" );

$im->borderImage( $bordercolor, 10, 10);

$page = array();

$page = $im->getImagePage();

$owidth = $page["width"];

$oheight = $page["height"];

$im->setImagePage( $owidth, $oheight, 0, 0);

$im->writeImage( $output );


}

catch(Exception $e)
{
        echo $e->getMessage();
}


// End loop
}

// Stop timer
$script_end = microtime_float();

// Calculate the run time
$run_time = ( round( $script_end, 4 ) - round( $script_start, 4 ));

// Calculate the average run time
$average = $run_time/$run;

// Display the average run time
echo "<br><p><b>Average time = $average </b></p>";

// Delete the image created
//unlink($output);
echo "<img src=\"$output\" border=1>";

?>	
Here is the result:

Image


Here is the PHP exec equivalent code:

Code: Select all

<?php

// Timer function
function microtime_float()
{
    list($utime, $time) = explode(" ", microtime());
    return ((float)$utime + (float)$time);
}

echo "PHP Loop exec command<br>";	

// Input image name if used
$image = "testoutline1.png";

// Output image name
$output = "testbulge1_exec.png";

// How many time to run
$run = "1";

// Setup default cycle time
$time = "";

// Command to use
$cmd = "-virtual-pixel white -gravity center -background white -extent 935x169 -distort barrelinverse \"0 0 0 1   0 0 -0.1 1.1\" -trim -bordercolor white -border 10 +repage ";

// Start timer
$script_start = microtime_float();

// Loop through the code
For ( $i=1; $i <= $run; $i++ ){

// Run the command
// Create an empty error array
$out = array();

exec("/usr/local/bin/convert $image $cmd $output", $out, $returnval);

// End loop
}

// Stop timer
$script_end = microtime_float();

// Calculate the run time
$run_time = ( round( $script_end, 4 ) - round( $script_start, 4 ));

// Calculate the average run time
$average = $run_time/$run;

// Display the average run time
echo "<br><p><b>Average time = $average </b></p>";

// Delete the image created
//unlink($output);
echo "<img src=\"$output\" border=1>";

?
>


Here is the result:

Image

Perhaps Imagick has not kept up with possible edits that Anthony has made to the -distort barrelinverse code. Or perhaps there is an error in dealing with a negative coefficient as in this case.

I hope the Imagick developer, mkoppanen, can take a look and comment.

Thanks

Fred

P.S. Tests were using: PHP 5.1.6; Imagick 3.00RC1 and IM 6.6.2-9 and 6.6.3-0
Post Reply