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

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

I tried to resizeImage

, scaleImage

, setImageResolution

and I tried to write in .png, but the result is very bad. I tried to set the compression quality to 100 and I tried various resizeImage and blur options.

$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 read somewhere about similar Ghostscript related issues, I have a Ghostscript port installed. How can I check if it works?

+3


source to share


2 answers


For the record, the solution was to mock the image through the shell:

eg.



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

      

+1


source


You must set the render resolution before reading the file:

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

      



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

+1


source







All Articles