Page 1 of 1

I need help

Posted: 2018-08-24T12:47:21-07:00
by ismael.ledezma
Hello guys i need help with imagic, i try to convert pdf into png, but i have this result.

https://drive.google.com/open?id=1uCGsS ... bM2nwB6EAJ

i need help

this is my code.<br/>
if($numrows==0){
if($categoria[$count] == "Selecciona")
$categoria[$count] = "GENERAL/";
$query = "INSERT INTO bas_indice (index_path,tag,uid,index_name,book_name) values ('$bookpath','$categoria[$count]','$uid','$directory','$libro');";
$con = pg_connect($conexion) or die ('No se pudo conectar: '.pg_last_error());
$resultado = pg_query($con,$query) or die("Error en la consulta SQL");
$count = $count + 1;
pg_close($con);
for ($i=0; $i < $numberpg; $i++) {
if (!file_exists($bookpath."/".$directory."_".$cliente."_".$i.".png")){
$objImgick->readImage("{$file}[$i]"); //El pdf
$objImgick->setImageFormat('png');//Asigna el formato de la imagen
$objImgick->writeImage($bookpath."/".$directory."_".$cliente."_".$i.'.png');
$objImgick->clear();//Borra la cache de la imagen
$objImgick->destroy();//Destruye el objeto imagen
}
}
this problem occurs in any file that contains text.

my specs
Ubuntu 18.04
php 7.2
apache2
16 gb ram
i5 6ta

P.D.
Sorry for my bad english <E>:lol:</E> and thank you for any help</r>

Re: I need help

Posted: 2018-08-24T12:54:05-07:00
by snibgo
What version of IM do you use? What version of Ghostscript?

If Ghostscript is older than 9.19, or is 9.22, I suggest you upgrade it.

If that doesn't help, please link to your input PDF.

Re: I need help

Posted: 2018-08-24T12:56:33-07:00
by fmw42
I am no expert, but your code does not look like Imagick code. And I do not see Imagick initialized.

See http://us3.php.net/manual/en/book.imagick.php

Re: I need help

Posted: 2018-08-24T14:34:39-07:00
by ismael.ledezma
Thanks for the help, this is IM info.
this is my version:
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
-----------------------------------------------
ghostcript version:
sistemas@sistemas01:~$ dpkg -l | grep ghostscript
ii ghostscript 9.22~dfsg+1-0ubuntu1.1 amd64 interpreter for the PostScript language and for PDF
ii ghostscript-x 9.22~dfsg+1-0ubuntu1.1 amd64 interpreter for the PostScript language and for PDF - X11 support

Re: I need help

Posted: 2018-08-24T14:37:54-07:00
by ismael.ledezma
fmw42 wrote: 2018-08-24T12:56:33-07:00 I am no expert, but your code does not look like Imagick code. And I do not see Imagick initialized.

See http://us3.php.net/manual/en/book.imagick.php
this is my full code, sorry, Ijust put the conversion part.

if(isset($_POST["cate"]) && !empty($_POST["cate"])){
if(isset($_POST["uid"]) && !empty($_POST["uid"])){
if(isset($_POST["cliente"]) && !empty($_POST["cliente"])){
if(isset($_POST["createbook"]) && !empty($_POST["createbook"])){
if(isset($_POST["libro"]) && !empty($_POST["libro"])){
//*Interactua: bookviews.js
//*Funcion: getbookselected()
//*Sirve: Convierte el pdf en imagenes para poder utilizarlo como paginas en el libro
//*Regresa: No regresa ningun valor
$categoria = $_POST["cate"];
$uid = $_POST["uid"];
$index = $_POST["createbook"];
$cliente = $_POST["cliente"];
$libro = $_POST["libro"];

$query = "";
$count = 0;
foreach ($index as $data) {
$con = pg_connect($conexion) or die ('No se pudo conectar: '.pg_last_error());
$objImgick = new Imagick(); //Instanciamos la libreria Imagick
$file = $data;
$path_name = pathinfo($file);
$directory = $path_name['filename'];

$bookpath = "paquete/$cliente/book/$directory/";
$objImgick->pingImage($file);
$numberpg = $objImgick->getNumberImages();
$html = "";
//Si no existe el directorio lo crea
if (!file_exists($bookpath)){
mkdir($bookpath, 0777, true);
}
//Verifica que no exista el indice
$valida ="SELECT index_path FROM bas_indice WHERE index_path = '$bookpath' AND uid = '$uid' AND book_name = '$libro' limit 1;";

$existe = pg_query($con,$valida);
$numrows = pg_num_rows($existe);
pg_close($con);
if($numrows==0){
if($categoria[$count] == "Selecciona")
$categoria[$count] = "GENERAL/";
//Hace la insercion en la base de datos
$query = "INSERT INTO bas_indice (index_path,tag,uid,index_name,book_name) values ('$bookpath','$categoria[$count]','$uid','$directory','$libro');";
$con = pg_connect($conexion) or die ('No se pudo conectar: '.pg_last_error());
$resultado = pg_query($con,$query) or die("Error en la consulta SQL");
$count = $count + 1;
pg_close($con);
//Crea las imagenes apartir del pdf
for ($i=0; $i < $numberpg; $i++) {
if (!file_exists($bookpath."/".$directory."_".$cliente."_".$i.".png")){
//$objImgick->setSize(1115,1443); //Resolucion de la imagen
$objImgick->readImage("{$file}[$i]"); //El pdf
$objImgick->setImageFormat('png');//Asigna el formato de la imagen
$objImgick->writeImage($bookpath."/".$directory."_".$cliente."_".$i.'.png');//Crea la imagen en la carpeta, con el nombre del archivo, el cliente y un id
$objImgick->clear();//Borra la cache de la imagen
$objImgick->destroy();//Destruye el objeto imagen
}
}

}
chmod($bookpath, 0777);
}
}
}
}
}
}

Re: I need help

Posted: 2018-08-24T14:44:39-07:00
by fmw42
Sorry, I do not know much about Imagick. So you will need help from someone who actually uses it.

Have you tried creating a simple Imagick command to test that it works independent of any database calls. That is usually a good way to test and develop. Get a small part working, then keep adding until it breaks and figure out then what caused the break.

Re: I need help

Posted: 2018-08-24T15:05:52-07:00
by snibgo
I suggest you provide a link to your input PDF, so we can try conversions with different versions of IM and Ghostscript.

Re: I need help

Posted: 2018-08-24T15:10:00-07:00
by fmw42
Following up with what user snibgo has said, do you have Ghostscript installed in your ImageMagick and can PHP Imagick find it. Often with PHP Imagick, it cannot use the same ENV variables as ImageMagick and so cannot find Ghostscript. To solve that, you must add the full path to "gs" within any line for PS, PDF, EPS, that call "gs" in the delegates.xml file.

You should write a simple PHP Imagick call that simply converts a PDF file to say PNG or TIFF or JPG and see if that works. Do not include any database or variables, just write code that does the convert and see if the result looks correct.

Re: I need help

Posted: 2018-08-24T16:38:43-07:00
by ismael.ledezma
hello good afternoon, we had already tried the ghostscript, the problem is apparently the version of php 7.2, which comes to install on ubuntu 18, we did the installation on a server with ubuntu 16, which has php 7.0 and worked perfectly, I do not know the reason for this error but the solution we could do was to make a downgrade of the operating system.

thanks for the help