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