problem when trying to convert pdf to jpg

MagickWand for PHP is an object-oriented PHP interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning MagickWand for PHP.
Post Reply
chrisweb

problem when trying to convert pdf to jpg

Post by chrisweb »

Hello,

im an imagemagick newbie ... It would be great if somebody could help me out ;)

i try to use magickwand to convert pdfs files to jpg files, i need something thats really fast, i want to use magickwand cause i want to make a multithreading application which can convert multiple pdf files at once

heres the error msg i get:

Fatal error: magickreadimage(): An unknown C API exception occurred [on C source line 392] in C:\xampp\htdocs\starterkit\public\wandtest.php on line 13

heres my source code:

Code: Select all

<?php

$mw = newMagickWand();
$file = 'test.pdf';

if ($in) {
        
	MagickSetSize($mw, 300, 300);
	MagickSetResolution($mw, 300, 300);
            
}

MagickReadImage($mw, $file); // this is line 13 // this line produces the error i get

MagickResetIterator($mw);

MagickSetImageFormat($mw, 'JPG');
MagickSetCompressionQuality($w, 85);
MagickWriteImage($mw, 'test.jpg');

header('Content-Type: image/'.$ext);
MagickEchoImageBlob($mw);
please, i need help, i should probably not mention it ;) , but i need to get this working before the end of the week :( , if nobody can help me, i will try to rewrite my code and use imagick instead, but if theres a chance to get it working i would prefer if i could use wand and i would be really happy and thankfull ;)

oh before i forget ... i did not fand the latest wand dll for windows, thats why i used the one which can be found here: http://theillustratedlife.com/php-5.2.0 ... q16_st.dll unfortunytly i dunno which version it is, or how old it is
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: problem when trying to convert pdf to jpg

Post by el_supremo »

ImageMagick (and MagickWand) uses Ghostscript as a "delegate" to read the PDF file and my guess is that you haven't got Ghostscript installed so your script crashed as soon as it tried to read test.pdf.
I am not familiar with PHP at all so I can't help you any more than to suggest you install Ghostscript and try again.
However, one note - the "st" on the end of the DLL's filename suggests that it is Single Threaded so it probably won't do what you want anyway.

Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
chrisweb

Re: problem when trying to convert pdf to jpg

Post by chrisweb »

el_supremo wrote:ImageMagick (and MagickWand) uses Ghostscript as a "delegate" to read the PDF file and my guess is that you haven't got Ghostscript installed so your script crashed as soon as it tried to read test.pdf.
thx for your fast reply and trying to help out, yes your right you need ghostscript to do this, i have installed ghostscript and i think its configured correctly, at least i hope

does somedody use magickwand to convert pdf files and does not get errors? perhaps theres something wrong whith my ghostscript installation, i dont know, if somedody could confirm that my code works well if ghostscript is installed correctly then i could try to reinstall ghostscript until it works
el_supremo wrote:I am not familiar with PHP at all so I can't help you any more than to suggest you install Ghostscript and try again.
However, one note - the "st" on the end of the DLL's filename suggests that it is Single Threaded so it probably won't do what you want anyway.

Pete
thx for the advise, hmmm yes this there is an st, but i think (although im not sure) the st means that magickwand will not use work in st on multi-core servers, in php there is no real multithreading, we use for example curl to call the magickwand api multiple times on a remote server which should convert the files, then the core server makes a ftp connection to the remote server to fetch all files which have been converted

if i use image magick and for example execute it per command line to convert multiple files, it will convert them one after the other, but if i use magickwand and curl to open multiple request at once, then the files get convert alltogether, not really alltogether cause the server memory and cpu are at 100% but at least some files at once, i did tests which a script which should convert gif files to png, it worked very well, magickwand was able to save a big amount of time, but it does not work if i try to convert pdf files :(
Post Reply