How to convert an image to base64 encoding?

前端 未结 9 1345
刺人心
刺人心 2020-11-22 06:01

Can you please guide me how can I convert an image from a URL to base64 encoding?

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 06:41

    Easy:

    $imagedata = file_get_contents("/path/to/image.jpg");
                 // alternatively specify an URL, if PHP settings allow
    $base64 = base64_encode($imagedata);
    

    bear in mind that this will enlarge the data by 33%, and you'll have problems with files whose size exceed your memory_limit.

提交回复
热议问题