从PHP / GD资源获取图像mimetype? [英] Get image mimetype from resource in PHP/GD?

查看:115
本文介绍了从PHP / GD资源获取图像mimetype?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到图像的MIME类型。 PHP有函数 getimagesize ,但只需要一个文件名,而我有一个图像资源,而不是 - 即从 imagecreatefromstring $ b

我找到了函数 imagesx imagesy 它从资源返回宽度/高度,但我找不到任何函数告诉我来自资源的MIME类型。任何人都知道如何做到这一点?



注意:由于设置了一个奇怪的服务器,我们无法读取/写入文件服务器通常只能通过一个FTP层(这是我从中读取图像数据的地方)。 我知道这是很老,但为了防止有人像我这样做过这个帖子......



更好的选项是从PHP 5.4.0发布的:
< a href =http://www.php.net/manual/en/function.getimagesizefromstring.php =noreferrer> getimagesizefromstring



这个新功能与getimagesize完全一样,但允许您从流中获取信息。


I'm trying to find the mime type of an image. PHP has the function getimagesize but that only takes a filename, whereas I have an image "resource" instead - i.e. an image created from imagecreatefromstring.

I found the functions imagesx and imagesy which return the width/height from a resource but I can't find any function that tell me the mime type from a resource. Anyone know of a way to do this?

Note: Due to a weird server set up, we can't read/write files from the server normally, only through an FTP layer (which is where I read the image data from).

解决方案

I know this is pretty old, but just in case someone come across this post like I did...

A better option it's been released from PHP 5.4.0: getimagesizefromstring

This new function is exactly the same of getimagesize but allows you to retreive the information from a stream.

这篇关于从PHP / GD资源获取图像mimetype?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆