1

I need some help on converting PNG files to JPG. I tried this stack but with no success. Can you help me?

HTML

<div class="custom-file">
<input type="file" class="custom-file-input" id="logo" name="logo" / >
<label class="custom-file-label" for="logo"></label>
</div>

LARAVEL

$imageName = time().'.'.$request->logo->getClientOriginalExtension();
$request->logo->move(public_path('/dist/img/logo'), $imageName);
$company->logo                      = $imageName;  
$company->save(); 

3 Answers3

1

At first install this Library . http://image.intervention.io/getting_started/installation

in controller import it,

use Intervention\Image\Facades\Image;

change in your code

$image = $request->file('logo');
$imageName = time().'.'."jpg";

Image::make($image)->encode('jpg', 65)
            ->save(public_path('/dist/img/logo' . $imageName));
$company->logo                      = $imageName;  
$company->save(); 
Anik Anwar
  • 625
  • 5
  • 11
0

This will help you :

$clientFile = pathinfo($_FILES['logo']['name']);
if($clientFlie['extension'] == 'png'){ 
    $ImageNameWithNewExtensionForClient = $clientFile['filename']."jpg";
 }

after you can move $ImageNameWithNewExtensionForClient to any path you want.

Mohamed Reda
  • 136
  • 1
  • 11
0

May be your JPG Support is disabled. please check using phpinfo().

Reference Link: https://stackoverflow.com/a/18821624/9533638

OR

you can use this one to convert png image to jpg. it will work.

=> https://github.com/free-open-source/php-image-converter/blob/master/src/ImageConverter.php