CodeIgniter Forums
Help Image Manipulation Class - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Help Image Manipulation Class (/showthread.php?tid=86971)



Help Image Manipulation Class - randyshare - 03-01-2023

How To rename extension that use Convert() method ?

my code below does not automatically rename file extension 

PHP Code:
        
        $img 
$this->request->getFile('image');
        $newimage $img->getRandomName();

        \Config\Services::image()
            ->withFile($newimage)
            ->resize(1360768false'auto')
            ->convert(IMAGETYPE_WEBP)
            ->save(FCPATH '/img/');
        $img->move(WRITEPATH '../public/img/');

        dd($img->getName()); 

My output file name still jpg/png
I need webp extension output filename.
Please help.


RE: Help Image Manipulation Class - InsiteFX - 03-02-2023

How To Convert JPG, PNG, GIF, And WebP In PHP With Practical Examples


RE: Help Image Manipulation Class - luckmoshy - 03-02-2023

PHP Code:
$img $this->request->getFile('image');
        $newimage =str_ireplace(['.jpg','.png','jpeg'],'.webp'$img->getRandomName());

        \Config\Services::image()
            ->withFile($newimage)
            ->resize(1360768false'auto')
            ->convert(IMAGETYPE_WEBP)
            ->save(FCPATH '/img/');
        $img->move(WRITEPATH '../public/img/');

        dd($img->getName()); 



RE: Help Image Manipulation Class - randyshare - 03-02-2023

(03-02-2023, 01:02 AM)luckmoshy Wrote:
PHP Code:
$img $this->request->getFile('image');
        $newimage =str_ireplace(['.jpg','.png','jpeg'],'.webp'$img->getRandomName());

        \Config\Services::image()
            ->withFile($newimage)
            ->resize(1360768false'auto')
            ->convert(IMAGETYPE_WEBP)
            ->save(FCPATH '/img/');
        $img->move(WRITEPATH '../public/img/');

        dd($img->getName()); 

thanks sir, it's work .