简体   繁体   中英

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?

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

My suggestion is: You have to use gdal2tiles.py to convert your .tif file into .png.

gdal2tiles Documentation

When you run this command its create an output folder, in which you get openlayers.html file, open it and see your .tif file in every browser easily.

If you need any help related to this, do comment. I'll guide you.

Don't use intervention I remove it from the import and install Imagick so to use the Imagick extension, you will first need to install it on your server and then update your code to use the Imagick functions instead of the GD functions. Here is an examp…

$imagick = new \Imagick();
$imagick->readImage('input.tif');
$imagick->setImageFormat('png');
$imagick->writeImage('output.png');

Alternatively, you could use a command-line tool like ImageMagick to convert the TIFF image to a PNG image. You can then use the PHP exec() function to call the ImageMagick command from your PHP code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM