PHP:如何将图像从URL转换为Base64?

问题描述:

我想将图像从其URL转换为base64.

I want to convert image from its url to base64.

是否要创建数据URL?然后,您需要MIME类型和其他一些信息(请参见 Wikipedia ).如果不是这种情况,则将是该图像的简单base64表示形式:

Do you want to create a data url? You need a MIME-Type and some other additional information then (see Wikipedia). If this is not the case, this would be a simple base64 representation of the image:

$b64image = base64_encode(file_get_contents('path/to/image.png'));

相关文档: base64_encode()-功能

Relevant docs: base64_encode()-function, file_get_contents()-function.