To convert a PDF file to an image, whether in windows or linux, you must first install the Imagick extension. This extension provides detailed installation tutorials and flexible installation. The code for implementing the function is as follows:
$ FileName1 = 'cz2016-01-01/o_1ak57jr6ms741efo1ndk8b4daic.jpg '; $ path1 =" http://img.qkhl.net/test "; Chmod ($ path1 .'/'. $ fileName1, '-rwxrwxrwx'); // assign the file permission (777) $ data_ I = 20.2png ($ fileName1, $ path1); die ('{"status" s: "success", "result": {"imgpath ":"'. $ data_ I. '"}'); // The return parameter function defaults 2png ($ pdf, $ path1, $ page =-1) {if (! Extension_loaded ('imagick') {return 4;} if (! File_exists ($ pdf) {return 5 ;}$ im = new Imagick (); $ im-> setResolution (60, 60 ); // Set the Resolution $ im-> setCompressionQuality (10); // set the image compression quality if ($ page =-1) {$ ss = $ im-> readImage ($ pdf);} else {$ im-> readImage ($ pdf. "[". $ page. "]"); // read the image return 7 from the file name;} $ im-> setImageFormat ('jpg '); // Set the specified format for the image $ filename1 = $ path1 ."/". md5(time().'.jpg '; $ dd = $ im-> writeImage ($ filename1); // return 'stopped'; if ($ dd = true) // write the image to the specified file {// return 'yes'; $ return = $ filename1;} else {return 'failed';} return $ return ;}
Note that 2png ($ pdf, $ path1, $ page =-1) is directly referenced when the function is introduced. In addition, the path must be correctly written; otherwise, the conversion will fail.