Image Magick error - ImagickException - Postscript delegate
Posted: 2012-01-26T02:21:40-07:00
Good morning.
I write because I needed to create a JPG of the first page of a PDF.
Buscand, I found the need to install ImageMagick on the server and ghostscript
I asked my hosting to install it and they confirmed that everything was installed.
The PHP info shows the following:
The programming code that I use is very simple:
And the error that is:
Thanks and best regards.
Javier
I write because I needed to create a JPG of the first page of a PDF.
Buscand, I found the need to install ImageMagick on the server and ghostscript
I asked my hosting to install it and they confirmed that everything was installed.
The PHP info shows the following:
The programming code that I use is very simple:
Code: Select all
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
if (isset($_FILES["files"]) && !$_FILES["files"]["error"][0])
{
$file_extension = explode(".", $_FILES["files"]["name"][0]);
$file_extension = array_pop($file_extension);
//echo("Copiamos [".$_FILES["files"]["tmp_name"][0]."] en el siguiente destino [".$MOD_CLINICALGUIDELINES_config["FILES_DIR"].$id.".".$file_extension."]");
copy($_FILES["files"]["tmp_name"][0], "../images/guias_clinicas/files/prueba.pdf");
// Generamos imagen PREVIEW del PDF mediante ImageMagick + Ghostscript
// Especificamos el nombre del fichero y la página a procesar
$img = new imagick("../images/guias_clinicas/files/prueba.pdf[0]");
// Configuramos la compresion, en este caso generamos un JPG, pero el formato puede ser cualquiera
// de los soportados por imagick
$img->setCompression(Imagick::COMPRESSION_JPEG);
$img->setCompressionQuality(70);
$img->setImageFormat("jpg");
// Generamos el <a href="http://www.apliweb.com/tag/thumbnail" class="st_tag internal_tag" rel="tag" title="Entradas etiquetadas con Thumbnail">thumbnail</a>, indicando ancho y alto, si uno de los 2 parametros es 0, se ajustara la
// imagen al otro manteniendo las proporciones
$im->thumbnailImage(150, 0);
// Podemos escribir ahora en un fichero la imagen y almacenarla o mostrar por pantalla directamente:
// Si la queremos almacenar:
$img->writeImages("../images/guias_clinicas/files/prueba_thumb.jpg", true);
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Thumb PDF</title>
</head>
<body>
<form method="post" action="<?php echo($_SERVER["PHP_SELF"]); ?>" enctype="multipart/form-data">
<input type="File" name="files[]"><br>
<input type="Submit" value="Enviar">
</form>
</body>
</html>
And the error that is:
I hope you can help:)Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `../images/guias_clinicas/files/prueba.pdf': @ error/pdf.c/ReadPDFImage/645' in /var/www/vhosts/XXXXXXXX/httpdocs/the_proyect/thumb_pdf.php:15 Stack trace: #0 /var/www/vhosts/XXXXXXXX/httpdocs/the_proyect/thumb_pdf.php(15): Imagick->__construct('../images/guias...') #1 {main} thrown in /var/www/vhosts/XXXXXXXX/httpdocs/the_proyect/thumb_pdf.php on line 15
Thanks and best regards.
Javier