I'm very new to PHP and this is the very first time I've tried to use Imagick, so there must be plenty wrong with the script I wrote in order to achieve my goal. :-)
What I'd like to do:
I wrote a function that's supposed to do it, but, as you guessed, it doesn't do anything at all:
function convertAndBlur($inputIMG, $dst, $width, $quality) {
$img = new Imagick($inputIMG);
$img->scaleImage($width, 0, true); // keep aspect ratio
$img->setImageFormat('jpeg');
$img->setImageCompressionQuality($quality);
$img->writeImage($dst . ".jpg");
$imgBlur = new Imagick($img);
$imgBlur->blurImage(5,3);
$imgBlur->writeImage($dst . "_blur.jpg");
$img->clear(); $img->destroy();
$imgBlur->clear(); $imgBlur->destroy();
}
The function is called this way:
$picture = $_FILES["picture"]["tmp_name"];
$pictureName = "foo";
if(!is_image($picture)) { die("not an image"); }
$picturePath = "uploads/" . $pictureName;
convertAndBlur($picture, $picturePath, 1000, 90);
This will certainly make some of you roll their eyes, but again, that's completely uncharted territory to me. Could anyone help me out? Thanks!
Imagick
's constructor cannot take an instance of Imagick
as an argument. To create another object, try $imgBlur = clone $img;
in place of $imgBlur = new Imagick($img);
, which will create a carbon copy of $img
. Read more about cloning Imagick
objects here.