Abdus Sattar Bhuiyan
Abdus Sattar Bhuiyan

Reputation: 3074

change image format using Imagick()

I want to change image file as jpeg format as follows:

$img_real_path = realpath(".") . "/" .$dest;
echo $img_real_path;
$image = new Imagick();
$image->readImage($img_real_path);
$image->setImageFormat("jpeg");

But image format is same as it was. What am I doing wrong?

Upvotes: 0

Views: 1023

Answers (1)

Viktor Svensson
Viktor Svensson

Reputation: 755

You're not using $image->imageWriteFile()

Add this to your code:

$image->imageWriteFile (fopen ($image_real_path, "wb"));

It should look like this:

$img_real_path = realpath(".") . "/" .$dest;
echo $img_real_path;
$image = new Imagick();
$image->readImage($img_real_path);
$image->setImageFormat("jpeg");
$image->imageWriteFile (fopen ($image_real_path, "wb"));

Upvotes: 2

Related Questions