phpimagebase64

How to convert an image to Base64 encoding


How can I convert an image from a URL to Base64 encoding?


Solution

  • I think that it should be:

    $path = 'myfolder/myimage.png';
    $type = pathinfo($path, PATHINFO_EXTENSION);
    $data = file_get_contents($path);
    $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);