Forum Moderators: coopster
i found a script snippet that should perform this:
$filename = "foo";
$file1 = "/Library/WebServer/Documents/polo/pdf/$filename.pdf";
$file2 = "/Library/WebServer/Documents/polo/jpg/$filename.jpg";
$result1 = @exec("/sw/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=jpeg
-sOutputFile=$file2 $file1 2>&1");
$result2 = @exec("/usr/local/bin/convert -resize 120x120 $file2
$file2 2>&1");
i altered this to this
$filename = "norden";
$file1 = "$filename.pdf";
$file2 = "$filename.jpg";
$result1 = exec("/usr/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=jpeg -sOutputFile=$file2 $file1 2>&1");
$result2 = exec("/usr/bin/convert -resize 120x120 $file2 $file2 2>&1");
if($result1 && $result2)
{echo "something happend";}
i made a directory with chmod 777 and loaded this script and a pdf called norden.pdf up. when i call this script
"something happens " appears but no jpg is created.
does anyone has a clue to me? maybe the file is crated
at the /usr/bin/ folder?
thanx for your help.
roland
that is a really interesting idea, quite common i want to do in the near future. but i did not solve your problem yet. can you tell me, why you added '2>&1' at the end of each commandline?
i just picked up an intereseting cmdparam of gs. you can setup the size in pixels of the output, in your case the jpeg. shouldn't this prevent you from using the second shellexec then? the param is:
-g<width>x<height> sizes are in pixel.
well because i completlly new with ghostscript and image magic i dont know where to start.
i made some changes to the script to get some failure messages. i thought it might be possible that the file is still in the php_temp folder so i tried to copy it to my webroot like this:
$filename = "norden";
$file1 = " /home/customer/april5.de/pdftest/$filename.pdf";
$file2 = " /home/customer/april5.de/pdftest/$filename.jpg";
$result1 = exec("/usr/bin/gs -q -dNOPAUSE -dBATCH -sDEVICE=jpeg -sOutputFile=$file2 $file1 2>&1");
copy ($result1 ,". /home/customer/april5.de/pdftest/files/".$file1);
$result2 = exec("/usr/bin/convert -resize 120x120 $file2 $file2 2>&1");
if($result1 && $result2)
{echo "something happend";
copy ($result2 ,". /home/customer/april5.de/pdftest/files/".$file2);
}
and here the output, finally an error message. but i don´t know how to handle this hint. i should try the url maybe :o)
Warning: Unable to open 'GNU Ghostscript 6.53: Unrecoverable error, exit code 1' for reading: Datei oder Verzeichnis nicht gefunden in /home/customer/april5.de/pdftest/mkjpg.php on line 16
something happend
Warning: Unable to open 'convert: Unrecognized option (-resize).' for reading: Datei oder Verzeichnis nicht gefunden in /home/customer/april5.de/pdftest/mkjpg.php on line 20
so it seems that ghostscript and imagemagick is found.
i will try some path options.
roland
if imagemagic is conifured with ghostwrite.
simply this Imagemagick command will create an jpg from a pdf file:
$filename="yourpdffilename"
$path2convert="yourpath"; //i.e. /usr/bin/
exec($path2convert."convert $filename.pdf[0] $filename.jpg");
pdf[0] the 0 means the first page of the pdf file
to resize the jpg i use the gd lib of php.
maybe someone give me a hint how to resize it at once
because the -resize option doesn´t work.
HTH
roland
often it's easy to ask google ;). i found a php class [hotscripts.com] (not tested on my own) which is well rated and a demo is available, too.
<?
$result1=exec("/usr/bin/convert norden.pdf[0] norden.jpg");
$file="norden.jpg";
$size = GetImageSize ("$file");
$hoch=120;
$breit=floor($size[0]/($size[1]/120));
$im = ImageCreateFromJPEG ($file);
$im2= ImageCreate ($breit, $hoch);
$breit2=$size[0]+1;
$hoch2=$size[1]+1;
imagecopyresized ($im2, $im, 0, 0, 0, 0, $breit, $hoch, $breit2, $hoch2);
$file3=substr("$file", 0,-4)."_tn.jpg";
imagejpeg ($im2, $file3, 75);
unlink ($file);
$newsize=GetImageSize ($file3)
?>
<img src="norden_tn.jpg" alt="" width="<?echo $newsize[0];?>" height="<?echo $newsize[1];?>" border="0">
convert -size 120x120 file.pdf -resize 120x120 thumbnail.jpg
maybe you'll have to add the [0] at the end of file.pdf again, but i don't know. i've taken it form the documentation [imagemagick.org].