imagick - PHP library object error -


i having issue imagick php library.

i doing recursive search in file system , pdf files.

    $it = new recursivedirectoryiterator("/test/project");     $display = array ('pdf');     foreach(new recursiveiteratoriterator($it) $file){         if (in_array(strtolower(array_pop(explode('.', $file))), $display))         {             if(file_exists($file)){                 echo $file;     //this echo /test/project/test1.pdf                 $im = new imagick($file);                 $im->setimageformat("jpg");                  file_put_contents('test.txt', $im);             }         }     } 

however, getting error saying

fatal error:  uncaught exception 'imagickexception' message 'can not process empty imagick object' in /test.php:57 stack trace: #0 /test.php(57): imagick->setimageformat('jpg') #1 {main}   thrown in /test.php on line 57  line 57  $im->setimageformat("jpg"); 

however, if replace $im = new imagick($file) $im = new imagick('/test/project/test1.pdf'), error gone.

i don't know why happening. can give me hint issue? much

as @pozs pointed out

note 1: $file variable object splfileinfo, using string.

here's code snippet gets filename string , has optimized method file extension:

<?php     $display           = array ('pdf');     $directoryiterator = new recursivedirectoryiterator('./test/project');      // key of iterator string filename      foreach (new recursiveiteratoriterator($directoryiterator) $filename => $file) {          // optimized method file extension         $fileextension = pathinfo($filename, pathinfo_extension);          if (in_array(strtolower($fileextension), $display)) {             if(file_exists($filename)){                 echo "{$filename}\n";                  // want imagick here             }         } 

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -