php - Fopen如何在php中读取png文件
问题描述
我正在做一些事情,我需要一个 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);
?>
推荐阅读
- r - 胜者/败者列联表
- javascript - 用 Javascript 计算方程
- amazon-web-services - 如何通过脚本将redshift集群快照从一个账户复制到另一个账户
- javascript - 表单(Ajax)在 KendoUI 模板中发布
- android - 在具有 3 个 dns 的局域网中连接时,如何使用特定的 dns 配置我的 android studio
- joomla - 如何在joomla的自定义代码事件中检索新添加行的id?
- html - CSS:将网格重构为具有不同子项的 flex 布局
- python - Python Fabric 2.4 没有环境变量
- mysql - 以下 mysql 语句的 groupby 替代方案
- matlab - Matlab:使用 ode 求解器的参数错误