让GD从二进制字符串中获取图像
我有一个数据库,将图像存储在 MySQL BLOB 字段中。 我设置了一个脚本,根据 URL 中的 ID 选择并显示图像,并且如果您附加 ?resize=800x600,它也会调整图像大小(在本例中为 800x600)。
我使用的主机没有安装Imagemagick,不让我自己做,所以我需要使用PHP的GD库来调整图像大小。
但我还没有找到像 Imagick 的 readImageBlob() 这样的函数,所以如果不先创建一个临时文件,编辑它,获取二进制文件,我就无法编辑从数据库获取的二进制字符串字符串,将其发送到浏览器,然后删除它(这步骤太多了,特别是当它投入生产时将获得几千次点击)。
所以我的问题是,有没有办法用PHP的GD复制readImageBlob
而不通过临时文件解决方案?
I have a database that stores images in a MySQL BLOB field. I setup a script that selects and displays the images based on an ID in the URL, and I also made it so if you append ?resize=800x600, it would resize the image (in this case, to 800x600).
The host that I use doesn't have Imagemagick installed and won't let me do it myself, so I need to use PHP's GD library to resize the image.
But I've yet to find a function like Imagick's readImageBlob()
, so I can't edit the binary string that I get from the database without first creating a temporary file, editing it, getting the binary string from it, sending it to the browser, and then deleting it (which is waaaay too many steps, especially since this will be getting a few thousand hits when it goes into production).
So my question is, is there any way to replicate readImageBlob
with PHP's GD without going through the temporary file solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
imagecreatefromstring() 应该可以解决问题。 我认为手册中的函数示例几乎正是您所需要的:
其中
$data
是数据库中的二进制数据字符串。imagecreatefromstring() should do the trick. I think the function example in the manual is almost exactly what you need:
Where
$data
is your binary data string from the database.