skip to Main Content

After uploading image I’m making one thumbnail image its work fine with PNG and jpg but when I upload gif image by default its get converted to PNG, how can I prevent this?

Here is my code

$img = Image::make(storage_path().'/app/public/images/'.$this->folderRoot.'/'.$this->imageName);
    $img->resize($this->size, null, function ($constraint) {$constraint->aspectRatio();});
    $img->save('storage/app/public/images/'.$this->folderRoot.$this->storeFolder.$this->resizedImageName,90);

experts put light on this.

2

Answers


  1. Try to pass the second parameter "format" like:

    Image::make(storage_path().'/app/public/images/'.$this->folderRoot.'/'.$this->imageName, ['format' => 'gif']);
    
    Login or Signup to reply.
  2. Try calling encode() before you save()

    $originalExtension = pathinfo(storage_path().'/app/public/images/'.$this->folderRoot.'/'.$this->imageName, PATHINFO_EXTENSION);
    
    $img->encode($originalExtension)->save('storage/app/public/images/'.$this->folderRoot.$this->storeFolder.$this->resizedImageName, 90);
    

    Or you try setting mime

    $format= $img->mime();
    $img->save('storage/app/public/images/'.$this->folderRoot.$this->storeFolder.$this->resizedImageName, 90, $format);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search