I downloaded this PNG image, which I suspect is the rose image you used:
http://www.imagemagick.org/Usage/compose/rose.png
My ImageMagick/imagick info is as follows (here culled from phpinfo.php):
imagick module version 3.4.0RC4
imagick classes Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version ImageMagick 6.9.2-0 Q16 x86 2015-09-10
http://www.imagemagick.org
Imagick using ImageMagick library version ImageMagick 6.9.2-0 Q16 x86 2015-09-10
http://www.imagemagick.org
ImageMagick copyright Copyright (C) 1999-2015 ImageMagick Studio LLC
ImageMagick release date 2015-09-10
I have the current versions of XAMPP (with PHP 7.01) and WAMP (with PHP 7.00).
On XAMPP, where I do most of my work, it created a black image. Then I tried it on WAMP, and...
...it produced an enlarged version of the original rose image, albeit a bit blurry as you had indicated.
My first thought was, "Wait, is XAMPP malfunctioning? Why did it work correctly in WAMP?" And so I then refreshed the screen in WAMP to run the routine again.
BINGO: It was BLACK.
And every refresh or hard-refresh produced the same result: a black image. Only the first time I had run it in WAMP had it converted correctly. Why? Hmm...
So, I downloaded other PNGs, and try as I might, they all converted to BLACK...from the first time on. It was only the first time I used the routine on WAMP after starting WAMP that it converted correctly...never again.
So, then I tried it on my live server...and...it worked every time, on both JPGs and PNGs. No problem whatsoever, no matter how many times I refreshed.
For some reason, after Imagick has been run on my localhost *once*, it ceases to handle PNG files...but it's fine with JPGs...they may be reprocessed indefinitely.
What follows is my complete testing script. Look at the bottom for the function call [ImagickResize()] where you feed in the prefix and extension (minus the ".") as arguments.
On my localhosts (both XAMPP and WAMP), when I run this repeatedly on the same JPG (by refreshing the screen), it runs anew, and it converts the JPG correctly and displays it correctly each time. On the other hand, it only produces *black* images for PNG files, except for the very first time it is run after first starting the localhost server. Perhaps that's a clue.
I'm using Windows 8.1 Pro.
P.S. Happy New Year!
Code: Select all
<?php
header( 'Content-type: text/html; charset=utf-8' );
while (@ob_end_flush());
function sendMsg($msg) {
echo $msg;
flush();
}
function ImagickResize($image_prefix, $ext) {
$server = 'live';
$separator = "/";
$basename = basename(__DIR__);
if (($_SERVER["REMOTE_ADDR"] == "127.0.0.1") || ($_SERVER["REMOTE_ADDR"] == "127.0.0.1/" . $basename . "/") || ($_SERVER["REMOTE_ADDR"] == "::1")) {
$server = 'localhost';
$separator = "/" . $basename . "/";
}
$source_image_file = $image_prefix . "." . $ext;
$source_image_path = $_SERVER['DOCUMENT_ROOT'] . $separator . $source_image_file;
$destination_image_file = $image_prefix . "-resized." . $ext;
$destination_image_path = $_SERVER['DOCUMENT_ROOT'] . $separator . $destination_image_file;
$w = "Initializing Imagick object...<br>";
sendMsg($w);
$im = new Imagick();
// Needed because of variable memory on shared live server:
if ($server == 'live') {
$im->setResourceLimit(imagick::RESOURCETYPE_MEMORY, 256);
$im->setResourceLimit(imagick::RESOURCETYPE_MAP, 256);
$im->setResourceLimit(imagick::RESOURCETYPE_AREA, 1512);
$im->setResourceLimit(imagick::RESOURCETYPE_FILE, 768);
$im->setResourceLimit(imagick::RESOURCETYPE_DISK, -1);
}
$source_image_size = filesize($source_image_file);
$source_image_size_in_MB = $source_image_size / 1000000;
$x = $source_image_file . " = " . $source_image_size_in_MB . " MB<br>";
sendMsg($x);
$y = "Working on $source_image_file ...<br>";
sendMsg($y);
$im->readImage($source_image_path);
$im->resizeImage(528, null, Imagick::FILTER_LANCZOS2SHARP, 1);
$im->setImageFormat("jpg");
$im->stripImage();
$im->writeImage($destination_image_path);
$im->clear();
$z = "Done.<br><br>";
sendMsg($z);
echo "<img src='" . $destination_image_file . "'>";
}
// Function parameters: ImagickResize([filename-prefix], [filename-extension-WITHOUT-DOT]);
// e.g.: ImagickResize("0", "jpg");
ImagickResize("rose", "png");
?>