0

I have below code and i got jpg image. but i want to get png image from byte data.

$image_string = 'byte_strng';
$data = base64_decode($image_string);
$im = imagecreatefromstring($data);
header('Content-Type: image/jpeg');
imagejpeg($im);
imagedestroy($im); 
Aspl Test
  • 133
  • 1
  • 10
  • 2
    Possible duplicate of [Convert JPG/GIF image to PNG in PHP?](https://stackoverflow.com/questions/8550015/convert-jpg-gif-image-to-png-in-php) – cgrim Nov 21 '18 at 10:58

3 Answers3

3

you can use this to get png data

header('Content-Type: image/png');
imagepng($im);
Nimesh Patel
  • 293
  • 1
  • 11
3

repalce jpeg to png you can change any type by just rename function and type.

    header('Content-Type: image/png');
    imagepng($im);
vishal melwani
  • 189
  • 1
  • 9
1
header('Content-Type: image/png');
imagepng($im);

Documentation: http://php.net/manual/en/function.imagepng.php

Khazul
  • 179
  • 6