Convert tiff to jpg in php?

后端 未结 3 644
梦如初夏
梦如初夏 2020-11-30 08:10

I have a server which holds TIFF images. Most clients can read and display TIFF images, so there\'s no problem. However, some clients can\'t handle this format but can handl

3条回答
  •  孤城傲影
    2020-11-30 08:29

    Tifs can have more than one page so a more comprehensive approach is needed. Here is an example:

        //given uploaded file $filename    
        $ext = strtolower(substr($filename, strrpos($filename, '.') + 1));
    
        if ($ext == 'tif' || $ext == 'tiff') {
            $images = new Imagick($upload_path . $filename);
    
            //if you want to delete the original tif
            unlink($upload_path . $filename);
    
            $name = strtolower(substr($filename, 0, strrpos($filename, '.')));
            $filename = $name . '.png';
            foreach ($images as $i => $image) {
                $image->setImageFormat("png");
                $image->writeImage($upload_path . $i . $filename);
            }
        }
    

提交回复
热议问题