CodeIgniter Forums
How to convert an image to WEBP mime type in CI? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: General (https://forum.codeigniter.com/forumdisplay.php?fid=1)
+--- Forum: Regional User Groups (https://forum.codeigniter.com/forumdisplay.php?fid=25)
+--- Thread: How to convert an image to WEBP mime type in CI? (/showthread.php?tid=84191)



How to convert an image to WEBP mime type in CI? - luckmoshy - 10-20-2022

Hi all! may someone help me with this issue, please!!

PHP Code:
public function createFile()
    {
 
  $file $this->request->getFile('image');

 

 \
Config\Services::image()->withFile($file)
 ->
convert(IMAGETYPE_WEBP)//it does not convert to real WEBP instead jpeg WHY?
 
->fit(300300'center')
 ->
save(FCPATH .'/image/'.$saveFile->store());

            $data=[
 
  'image'=> $saveFile
 
]; 
 
$model->save($data);
 } 



RE: How to convert an image to WEBP mime type in CI? - InsiteFX - 10-21-2022

PHP | imagewebp() Function


RE: How to convert an image to WEBP mime type in CI? - Ami Kariya - 10-27-2022

All other things being equal, WebP compresses the file more effectively than previous formats (png and jpeg), therefore it uses less hosting space and loads pages more quickly when viewed in a browser.

cwebp image.jpg -o image.webp

cwebp -q 100 image1.jpg -o image1.webp

cwebp -q 100 image2.jpg -o image2.webp

ls -lh image1.jpg image1.webp image2.jpg image2.webp

Then The output of the ls command shows that the size of your images 

Use the -lossless option in place of -q to save the entire, original data of photos during compression. The greatest option for preserving the quality of PNG images is this. Modifying the downloaded PNG image