1

I have picture url from Facebook in jpg format. But I can manage it in another code only if it is in base64 encoded png format. I don't want to rewrite entire module.

I have tried everything I found on Internet and nothing works.

The closest I solve this is

base64_encode(imagepng(imagecreatefromstring(file_get_contents($url))));

If you have some ideas I would like to hear them.

  • RTFM: http://php.net/imagepng unless you give it a filename, imagepng OUTPUTS the png data. it does NOT return the image. – Marc B Aug 31 '16 at 14:18
  • Yes, I found out in documentation. But I don't know how to do it another way. I want something like imagepng but It has to return image which suits base64_encode function. – Tomáš Hrušo Aug 31 '16 at 14:20
  • so write the png to a file, then base64 encode from that file, or use the output buffering system to capture imagepng's output, and then encode that. you have a lot of options, but NONE of them are going to be possible as a one-liner like you have. – Marc B Aug 31 '16 at 14:21

1 Answers1

0
  1. get image, file_get_contents('image.jpg');
  2. convert to png: Convert JPG/GIF image to PNG in PHP?
  3. do base 64: http://php.net/manual/en/function.base64-encode.php
Community
  • 1
  • 1
degr
  • 1,559
  • 1
  • 19
  • 37