【问题标题】:How can Fopen read png files in phpFopen如何在php中读取png文件
【发布时间】:2021-02-09 05:07:28
【问题描述】:

我正在做一些事情,我需要一个 png 文件中的数据,我只能使用 PHP。不要问为什么,只要给我答案,哈哈

【问题讨论】:

  • 定义“数据”——你需要的数据到底是什么?

标签: php fopen


【解决方案1】:

假设下面是你的图片。

您必须使用下面的行在变量中定义其 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);
?>

【讨论】:

  • 如果对您有帮助,请接受答案。
猜你喜欢
  • 2012-08-06
  • 1970-01-01
  • 2019-01-06
  • 2015-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-17
  • 2011-09-20
相关资源
最近更新 更多