1

I'm trying to generate an image from a downloaded document with imagick and then sending the Base64 on that image. My function works locally and generate the image. But when i run the code in production it doesn't work and throws me this error :

Uncaught PHP Exception ImagickException: "unable to open file /tmp/magick-1520139 jpiDdts9A7sW': No such file or directory @ error/constitute.c/ReadImage/599" at /var/www/html/backend/src/Controller/API/DocumentController.php line 1040 {"exception":"[object] (ImagickException(code: 430): unable to open file /tmp/magick-1520139jpiDdts9A7sW': No such file or directory @ error/constitute.c/ReadImage/599 at /var/www/html/backend/src/Controller/API/DocumentController.php:1040)"} []

Here the code :

 $result = $blobAzurService->downloadFileFromBlob($container, $title, $ext);

        rename('/var/www/html/backend/blobTmp/'.$title.'.'.$ext, "/var/www/html/backend/blobTmp/preview_".$title.'.'.$ext);

        $im = new \imagick();
        
        $im->setResolution(300,300);

        $im->readImage('/var/www/html/backend/blobTmp/preview_'.$title.'.'.$ext.'[0]');

        $im->setImageFormat('jpeg');

        $im->writeImage('/var/www/html/backend/blobTmp/preview_'.$title.'.jpeg');

        $image = file_get_contents('/var/www/html/backend/blobTmp/preview_'.$title.'.jpeg');

        unlink('/var/www/html/backend/blobTmp/preview_'.$title.'.'.$ext);
        unlink('/var/www/html/backend/blobTmp/preview_'.$title.'.jpeg');

        $im->destroy();

        $image = base64_encode($image);

So far what i've tried is to rename the downloaded image because I saw that the document might be destroyed before imagick reads it. But it didn't work, and I can't find a solution to this seemingly common issue

  • Does this answer your question? [Imagick: unable to open file](https://stackoverflow.com/questions/15446687/imagick-unable-to-open-file) – Ecstasy Apr 08 '22 at 10:27
  • I'm now using `$imagemagickisawful=substr($_SERVER['SCRIPT_FILENAME'], 0, strrpos($_SERVER['SCRIPT_FILENAME'], "/") )."/";` for my base path but it's still not working – Bill Louis Charles Apr 08 '22 at 12:42

0 Answers0