phpintervention

tif to pdf/png enocoding


I am working on application where input files having extension .tif(Tagged Image File Format (TIFF)). The basic problem is to display .tif files in all browser which is not applicable on all major browsers. The solution i have accept is to convert them into png

I have am converting .tif file to png using http://image.intervention.io/api/encode in PHP Laravel 5.5

Image intervention is depends on imagick for tif encoding, i have installed this dependency but the encoding scheme is converting/display/store first image from tif file, not all files.

Can any one have solution from tif to PNG or PDF conversion using any PHP library?


Solution

  • I found very nice article here, the approach to solve this problem is,

     $file = Storage::disk('s3')->get(request()->file_name);
     $file_pdf  =storage_path("app/bundle/tmp/".end($name).".pdf");
     $document =new  \Imagick();
     $document->readImageBlob($file);
     if (!$document->writeImages($file_pdf, true)) {
         echo "Unable to write the file";
     } else {
         $document->clear();
     }
     return response()->file($file_pdf)->deleteFileAfterSend(true);
    

    I have read s3 file stream using laravel storage and pass that blob using Imagick readImageBlob() method. The state of the art is $document->writeImages("to_pdf.pdf") file. At the end you can clear the file variable