RESOLVED-NO BUG: possible bug in resizeImage

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

RESOLVED-NO BUG: possible bug in resizeImage

Post by fmw42 »

This is resolved as no bug, but a typo on my part. I had put a blur=0 for default value, but it should have been 1.




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.

When I use resizeImage with the lanczos filter, the result is very aliased as if it was using a point filter or using sampleImage.

Here is the input image:
Image

Here is the code using Imagick to resize by 25%

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 = "testresize1_imagick.png";

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

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

$width = floor(0.25 * 935);

$height = floor(0.25 * 113);

// Start timer
$script_start = microtime_float();

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

try
{

$im = new Imagick();

$im->readImage( $image );

# erroneous default blur value used
#$im->resizeImage ( $width, $height, Imagick::FILTER_LANCZOS, 0, false ); 

# corrected default blur value
$im->resizeImage ( $width, $height, Imagick::FILTER_LANCZOS, 1, false );

$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 resulting CORRECTED image:

Image


Compare this to using PHP exec 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 = "testresize1_exec.png";

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

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

// Command to use
$cmd = "-filter lanczos -resize 25% ";

// 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 resulting image:

Image


It is possible that the IM filters have been changed since this version of IMagick. I know Anthony has made some significant changes over time. Perhaps Imagick has not kept up with those changes.

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