【发布时间】:2021-02-09 05:07:28
【问题描述】:
我正在做一些事情,我需要一个 png 文件中的数据,我只能使用 PHP。不要问为什么,只要给我答案,哈哈
【问题讨论】:
-
定义“数据”——你需要的数据到底是什么?
我正在做一些事情,我需要一个 png 文件中的数据,我只能使用 PHP。不要问为什么,只要给我答案,哈哈
【问题讨论】:
假设下面是你的图片。
您必须使用下面的行在变量中定义其 url
$image = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';
之后,您可以使用 file_get_content 函数来获取图像的数据/内容。
$image_content = file_get_contents($image);
另外,如果你想把它转换成base64字符串,你可以使用base64_encode函数。
$image_base64Data = base64_encode($image_content);
整个代码将......
<?php
$image = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png';
$image_content = file_get_contents($image);
$image_base64Data = base64_encode($image_content);
?>
【讨论】: