php gd imagecreatefromstring() 和图像 mime 类型
有没有办法使用 imagecreatefromstring() 并以某种方式获取图像类型?
is there a way to use imagecreatefromstring()
and get somehow what is the image type?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您使用 imagecreatefrom... 方法时,图像将作为未压缩的位图加载到内存中。此时还没有真正的图像类型。您可以使用 image... 功能将其保存为您想要的任何类型。
https://www.php.net/manual/en/function.imagecreatefromstring。 php
When you use imagecreatefrom... methods, the image is loaded into memory as the uncompressed bitmap. there is not really a image type at this point. you can save it back out as whatever type you wish using the image... function.
https://www.php.net/manual/en/function.imagecreatefromstring.php
在使用
imagecreatefromstring( $string )
之前,您提供的实际 $string 作为该函数的参数可以用于确定图像类型:来源:https://stackoverflow.com/a/6061602/3705191
您必须将获得的字符串与常见图像文件的 MIME 类型(
image/jpeg
、image/png
、image/gif
等)。检查此常见 MIME 类型列表参考。
Before using
imagecreatefromstring( $string )
, the actual $string you're providing as the argument for that function can be used to determine the image type:Credit: https://stackoverflow.com/a/6061602/3705191
You'll have to compare the string you get with the MIME type of common image files (
image/jpeg
,image/png
,image/gif
, etc.).Check this List of Common MIME Types for reference.