benedict_w
benedict_w

Reputation: 3608

Resizing .eps and Saving as .jpg with Imagick in PHP

I am trying to resize and save an .eps file to a .jpeg with Imagick,

I have tried resizeImage, scaleImage, setImageResolution, and I've tried writing to .png, but the result is always very bad. I've tried setting the compression quality to 100, and I've tried various resizeImage filter and blur params.

$imagick = new Imagick();
$imagick->readImage($file);

$imagick->resizeImage($width, $height, imagick::FILTER_CATROM, 1);

$imagick->setImageFormat('jpeg');

return $imagick->writeImage($name);

Is there some magic I am missing?

Edit: I've read somewhere about similar issues being Ghostscript related, I have the Ghostscript port installed. How can I verify it is working?

Upvotes: 3

Views: 3561

Answers (2)

AndreKR
AndreKR

Reputation: 33678

You have to set the render resolution before you read the file:

$imagick = new Imagick();
$imagick->setResolution(300, 300);
$imagick->readImage($file);

If the result is still bad, it means that ImageMagick is using the embeded TIFF preview from the EPS instead of the actual PostScript data. Make sure Ghostscript is installed and can be found as described in this answer.

Upvotes: 1

benedict_w
benedict_w

Reputation: 3608

For the record the solution was to execute image magick via the shell:

e.g.

$cmd = escapeshellcmd("convert -resize '{$width}x{$height}' -density 300 -flatten {$file} -colorspace rgb {$jpeg}");
exec($cmd, $out, $return_var);

Upvotes: 1

Related Questions