Welcome Guest, Not a member yet? Register   Sign In
in service:: image this method does not work !!! ??? convert()
#1

(This post was last modified: 01-25-2024, 09:45 PM by luckmoshy.)

Hi, Ci I think @kenjis one day if I am not mistaken promised to solve this issue at the next CI upgrade but till now is not been working why is it forgotten? or is there another way!!!

PHP Code:
$this->sizeImage =  \Config\Services::image(); 

PHP Code:
//does not work at all
  if($file->isValid() && ! $file->hasMoved()) {          
 
            $this
->sizeImage->withFile($file)
 ->
convert(IMAGETYPE_WEBP)
            ->fit(700,450,true,'center')
            ->save(FCPATH .'/upload/'.
 
$save $file->getRandomName()); 
          

but have used my way to generate and is working

like this


PHP Code:
//Here is working....
  if($file->isValid() && ! $file->hasMoved()) {          
 
            $this
->sizeImage->withFile($file)
 
//->convert(IMAGETYPE_WEBP)
            ->fit(700,450,true,'center')
            ->save(FCPATH .'/upload/'.
 
$save str_ireplace(['.jpg','.png','.jpeg'],'.webp',$file->getRandomName()); 
          
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#2

There is no issue about webp:
https://github.com/codeigniter4/CodeIgni...Aopen+webp

What's happened? The exact Error message?
Reply
#3

This bug has been fixed in v4.4.4:
https://github.com/codeigniter4/CodeIgniter4/pull/8210
Reply
#4

(This post was last modified: 01-26-2024, 08:20 PM by luckmoshy.)

(01-25-2024, 10:42 PM)kenjis Wrote: This bug has been fixed in v4.4.4:
https://github.com/codeigniter4/CodeIgniter4/pull/8210

Thank you @kenjis but I use the latest CI 4.4.4


this is how I use but not yet working

PHP Code:
//does not work at all

public function createFile(){
$this->sizeImage =  \Config\Services::image(); 

          $file $this->request->getFile('img');

  if($file->isValid() && ! $file->hasMoved()) {          
 
            $this
->sizeImage->withFile($file)
          ->convert(IMAGETYPE_WEBP)
            ->fit(700,450,true,'center')
            ->save(FCPATH .'/upload/'$save $file->getRandomName()); 
          }

$Model->save(['db_image'=>$save]); 


The file is saved but not converted to webp
is somewhere I may be wrong or ?? !!!
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply
#5

Are you usng GD ?
If so, remove `@` in the following and check to see if an error shows.

PHP Code:
--- a/system/Images/Handlers/GDHandler.php
+++ b/system/Images/Handlers/GDHandler.php
@@ -240,+240,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.gifNotSupported'));
                }

-
                if (! @imagegif($this->resource$target)) {
+
                if (! imagegif($this->resource$target)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
250,+250,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.jpgNotSupported'));
                }

-
                if (! @imagejpeg($this->resource$target$quality)) {
+
                if (! imagejpeg($this->resource$target$quality)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
260,+260,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.pngNotSupported'));
                }

-
                if (! @imagepng($this->resource$target)) {
+
                if (! imagepng($this->resource$target)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
270,+270,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.webpNotSupported'));
                }

-
                if (! @imagewebp($this->resource$target$quality)) {
+
                if (! imagewebp($this->resource$target$quality)) {
                    throw ImageException::forSaveFailed();
                }
                break; 
Reply
#6

(This post was last modified: 01-27-2024, 11:57 PM by luckmoshy.)

(01-26-2024, 08:49 PM)kenjis Wrote: Are you usng GD ?
If so, remove `@` in the following and check to see if an error shows.

PHP Code:
--- a/system/Images/Handlers/GDHandler.php
+++ b/system/Images/Handlers/GDHandler.php
@@ -240,+240,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.gifNotSupported'));
                }

-
                if (! @imagegif($this->resource$target)) {
+
                if (! imagegif($this->resource$target)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
250,+250,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.jpgNotSupported'));
                }

-
                if (! @imagejpeg($this->resource$target$quality)) {
+
                if (! imagejpeg($this->resource$target$quality)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
260,+260,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.pngNotSupported'));
                }

-
                if (! @imagepng($this->resource$target)) {
+
                if (! imagepng($this->resource$target)) {
                    throw ImageException::forSaveFailed();
                }
                break;
@@ -
270,+270,@@ class GDHandler extends BaseHandler
                    
throw ImageException::forInvalidImageCreate(lang('Images.webpNotSupported'));
                }

-
                if (! @imagewebp($this->resource$target$quality)) {
+
                if (! imagewebp($this->resource$target$quality)) {
                    throw ImageException::forSaveFailed();
                }
                break; 


Thank you, @kenjis, for replying. Sorry for the lateness; yes, I tested. No error and yes, i use GD


  Have you tried on your side? Is it working fine for me? I am using xamp local host with laragon  + latest CI 4+
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB