PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 10, 2022

[FIXED] how to convert webp image to jpeg or png by using intervention image laravel

 October 10, 2022     gd, image, intervention, laravel-5, webp     No comments   

Issue

I am developing an app in Laravel Framework (PHP). I want to upload image which have webp format and then convert it to jpeg or png image format. After converting the image i also want to upload it to s3 bucket.


Solution

Firstly we can use Intervention Image library. We must have php 7 and gd library installed. I am writing the commands to install gd library and webp library below (for ubuntu) :

sudo apt-get update
sudo apt-get install webp
sudo apt-get install php7.0-gd (check php version and then install accordingly)

now check file extension and if extension is webp, select your output file extension

$extension = $this->file->extension();

if($this->file->getMimeType() == 'image/webp'){
    $extension = 'png';
}
// Generate a random filename
$fileName = time() . '_' . strtolower(uniqid()) . '.' . $extension;

Now encode the image to desired format

if($this->file->getMimeType() == 'image/webp'){
    $image = $image->encode($extension);
}
$image = $image->stream();

Now upload the image to s3 bucket

Storage::disk('s3')->put($folderName . '/' . $fileName, $imageNormal->__toString());


Answered By - Tarun Dhiman
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing