位置: 编程技术 - 正文

PHP:getimagesize()的用法_GD库图像处理函数

编辑:rootadmin
getimagesize

推荐整理分享PHP:getimagesize()的用法_GD库图像处理函数,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

getimagesize — 取得图像大小

说明 array getimagesize ( string $filename [, array &$imageinfo ] )

getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型和一个可以用于普通 HTML 文件中 IMG 标记中的 height/width 文本字符串。

如果不能访问 filename 指定的图像或者其不是有效的图像,getimagesize() 将返回 FALSE 并产生一条 E_WARNING 级的错误。

Note:

对 JPC,JP2,JPX,JB2,XBM 和 WBMP 的支持自 PHP 4.3.2 起可用。对 SWC 的支持自 PHP 4.3.0 起可用。对 TIFF 的支持是 PHP 4.2.0 添加的。

Note: JPEG 支持是 PHP 4.3.2 添加的。注意 JPC 和 JP2 可以有不同的色彩深度的成分。此情况下,“bits”的值是碰到的最高的位深度。此外,JP2 文件可能包含有多个 JPEG 代码流,此情况下,getimagesize() 返回此文件顶层中碰到的第一个代码流的值。

Note: 本函数不需要 GD 图像库。

返回一个具有四个单元的数组。索引 0 包含图像宽度的像素值,索引 1 包含图像高度的像素值。索引 2 是图像类型的标记:1 = GIF,2 = JPG,3 = PNG,4 = SWF,5 = PSD,6 = BMP,7 = TIFF(intel byte order),8 = TIFF(motorola byte order),9 = JPC, = JP2, = JPX, = JB2, = SWC, = IFF, = WBMP, = XBM。这些标记与 PHP 4.3.0 新加的 IMAGETYPE 常量对应。索引 3 是文本字符串,内容为“height="yyy" width="xxx"”,可直接用于 IMG 标记。

Example #1 getimagesize(文件)

<?phplist($width,$height,$type,$attr)=getimagesize("img/flag.jpg");echo"<imgsrc="img/flag.jpg"$attr>";?>

URL 支持是 PHP 4.0.5 添加的。

Example #2 getimagesize(URL)

<?php$size=getimagesize("

对于 JPG 图像,还会多返回两个索引:channels 和 bits。channels 对于 RGB 图像其值为 3,对于 CMYK 图像其值为 4。bits 是每种颜色的位数。

自 PHP 4.3.0 起,bits 和 channels 对于其它图像类型也存在。但是这些值可能会把人搞糊涂。例如,GIF 总是对每个像素使用 3 个 channel,但是对于动画 GIF 来说每个像素的位数无法通过全局颜色表计算出来。

某些格式可能不包含图像或者包含多个图像。此种情况下,getimagesize() 可能不能用来准确测定图像的大小。此时 getimagesize() 将返回零作为宽度和高度。

自 PHP 4.3.0 起,getimagesize() 还会返回额外的参数 mime,符合该图像的 MIME 类型。此信息可以用来在 HTTP Content-type 头信息中发送正确的信息:

Example #3 getimagesize() 和 MIME 类型

<?php$size=getimagesize($filename);$fp=fopen($filename,"rb");if($size&&$fp){header("Content-type:{$size['mime']}");fpassthru($fp);exit;}else{//error}?>

可选的 imageinfo 参数允许从图像文件中提取一些扩展信息。目前,这将以一个关联数组返回不同的 JPG APP 标识。某些程序用这些 APP 标识来在图像中嵌入文本信息。一个非常常见的是 APP 标识中嵌入的 IPTC » 信息。可以用 iptcparse() 函数来将二进制的 APP 标识解析为可读的信息。

Example #4 getimagesize() 返回 IPTC

<?php$size=getimagesize("testimg.jpg",&$info);if(isset($info["APP"])){$iptc=iptcparse($info["APP"]);var_dump($iptc);}?>

参见 image_type_to_mime_type(),exif_imagetype(),exif_read_data() 和 exif_thumbnail()。

参数

filename PHP:getimagesize()的用法_GD库图像处理函数

This parameter specifies the file you wish to retrieve information about. It can reference a local file or (configuration permitting) a remote file using one of the supported streams.

imageinfo

This optional parameter allows you to extract some extended information from the image file. Currently, this will return the different JPG APP markers as an associative array. Some programs use these APP markers to embed text information in images. A very common one is to embed »IPTC information in the APP marker. You can use the iptcparse() function to parse the binary APP marker into something readable.

返回值

Returns an array with 7 elements.

Index 0 and 1 contains respectively the width and the height of the image.

Note:

Some formats may contain no image or may contain multiple images. In these cases, getimagesize() might not be able to properly determine the image size. getimagesize() will return zero for width and height in these cases.

Index 2 is one of the IMAGETYPE_XXX constants indicating the type of the image.

Index 3 is a text string with the correct height="yyy" width="xxx" string that can be used directly in an IMG tag.

mime is the correspondant MIME type of the image. This information can be used to deliver images with the correct HTTP Content-type header:

Example #5 getimagesize() and MIME types

<?php$size=getimagesize($filename);$fp=fopen($filename,"rb");if($size&&$fp){header("Content-type:{$size['mime']}");fpassthru($fp);exit;}else{//error}?>

channels will be 3 for RGB pictures and 4 for CMYK pictures.

bits is the number of bits for each color.

For some image types, the presence of channels and bits values can be a bit confusing. As an example, GIF always uses 3 channels per pixel, but the number of bits per pixel cannot be calculated for an animated GIF with a global color table.

On failure, FALSE is returned.

错误/异常

If accessing the filename image is impossible, or if it isn&#;t a valid picture, getimagesize() will generate an error of level E_WARNING. On read error, getimagesize() will generate an error of level E_NOTICE.

更新日志

版本 说明 5.3.0 Added icon support. 5.2.3 Read errors generated by this function downgraded to E_NOTICE from E_WARNING. 4.3.2 Support for JPC, JP2, JPX, JB2, XBM, and WBMP became available. 4.3.2 JPEG support was added for the imageinfo parameter. 4.3.0 bits and channels are present for other image types, too. 4.3.0 mime was added. 4.3.0 Support for SWC and IFF was added. 4.2.0 Support for TIFF was added. 4.0.6 Support for BMP and PSD was added. 4.0.5 URL support was added.

范例

Example #6 getimagesize() example

<?phplist($width,$height,$type,$attr)=getimagesize("img/flag.jpg");echo"<imgsrc="img/flag.jpg"$attralt="getimagesize()example"/>";?>

Example #7 getimagesize (URL)

<?php$size=getimagesize("

Example #8 getimagesize() returning IPTC

<?php$size=getimagesize("testimg.jpg",$info);if(isset($info["APP"])){$iptc=iptcparse($info["APP"]);var_dump($iptc);}?>

注释

Note:

此函数不需要 GD 图象库。

参见

image_type_to_mime_type() - 取得 getimagesize,exif_read_data,exif_thumbnail,exif_imagetype 所返回的图像类型的 MIME 类型 exif_imagetype() - 判断一个图像的类型 exif_read_data() - 从 JPEG 或 TIFF 文件中读取 EXIF 头信息 exif_thumbnail() - 取得嵌入在 TIFF 或 JPEG 图像中的缩略图

PHP:imageaffine()的用法_GD库图像处理函数 imageaffine(PHP5=5.5.0)imageaffine返回经过仿射变换后的图像,剪切区域可选说明resourceimageaffine(resource$image,array$affine[,array$clip])Warning本函数还未编写文档,仅

PHP:image2wbmp()的用法_GD库图像处理函数 image2wbmp(PHP4=4.0.5,PHP5)image2wbmp以WBMP格式将图像输出到浏览器或文件说明intimage2wbmp(resource$image[,string$filename[,int$threshold]])image2wbmp()从image图像创建一个名为f

PHP:image_type_to_extension()的用法_GD库图像处理函数 image_type_to_extension(PHP5)image_type_to_extension取得图像类型的文件后缀说明stringimage_type_to_extension(int$imagetype[,bool$include_dot=TRUE])根据给定的常量IMAGETYPE_XXX返回

标签: PHP:getimagesize()的用法_GD库图像处理函数

本文链接地址:https://www.jiuchutong.com/biancheng/288392.html 转载请保留说明!

上一篇:PHP:imagealphablending()的用法_GD库图像处理函数

下一篇:PHP:imageaffine()的用法_GD库图像处理函数(php imagettftext()函数)

  • 开模具厂一年能挣多少钱
  • 附加税申报减免性质代码下面的三个请选择用填吗
  • 所得税费按年缴纳?
  • 银行转账结算的方式有哪些
  • 会计中应收账款的英文
  • 应收账款减值后可以转回吗
  • 一般存款账户可以转账给个人吗
  • 增值税进项销项每个月需要结转吗
  • 房地产开发企业预收款预缴增值税
  • 报废资产处置收入怎么计税
  • 企业转增股本要交税吗
  • 金三系统打印控件下载及报税流程
  • 虚假享受税收优惠政策
  • 损益表和利润表的关系
  • 个体工商户是否需要缴纳印花税
  • 进项税额转出多转了怎么办
  • 上个月的费用这个月开发票怎么做账
  • 环保税计算方法和税率1.2
  • 所得税汇算清缴退税会计分录怎么做
  • 什么是补提或者计提
  • 以前年度的其他应付款不用付怎么处理
  • win11隐藏图标怎么弄出来
  • 减免增值税计入什么科目
  • 企业与企业之间借款账务如何处理
  • 印花税的计税依据是含税还是不含税
  • 如何启用系统引擎
  • php如何实现多线程
  • 存货销售收入
  • 老年人经常便秘怎么办
  • 固定资产八大类别
  • 安博塞利国家公园简介
  • eslint vue配置
  • 收回前欠货款存入银行的会计分录
  • php array操作
  • 二维码的实现原理和实现过程
  • php制作验证码
  • 代收水电费交税吗
  • java泛型E和T
  • 红票申请单怎么开
  • 汇总纳税企业所得税征收管理办法
  • phpcms v9用户手册
  • MySQL5.1忘记root密码的解决办法(亲测)
  • 股东投钱一般怎么投
  • 销售货物未收到货款的会计分录怎么写
  • 房屋出租收入是其他业务收入吗
  • 合同不交印花税怎么处理
  • 《中华人民共和国禁毒法》自( )起施行
  • SQLServer2005 Output子句获取刚插入的ID值
  • db2 select as
  • 通货膨胀率怎么求
  • 小规模纳税人企业所得税2023
  • 专利代理服务费如何记账
  • 建信融通e信通怎样转让
  • 无法收回的应收账款可以税前扣除吗
  • 收到汇算清缴后怎么做账
  • 会计行政法规包括哪些条例?具体说明?
  • 数据库中的内容怎么换行
  • mysql查询结果输出
  • 催化剂过低怎么解决
  • 隐藏的系统
  • win7系统升级到win10后,还能还原回来吗
  • 在linux系统中添加用户的命令
  • dwm exe是什么
  • 获取windows的最新信息
  • macbookair登陆
  • centos dvd安装
  • linux系统中怎么编写一个程序
  • linux不小心删除目录怎么恢复
  • linux shell echo
  • node.js怎么搭建服务器
  • 浅谈会计诚信与职业道德论文
  • Git 创建分支提交远程分支详解
  • bat 远程连接
  • 全面解析俄乌武器对比
  • Activity与Theme
  • 税务局稽查科有什么处理企业的办法
  • 滴滴收入统计
  • 陕西地方税务局2017年2号公告
  • 新领取的发票怎么读入金税盘
  • 金融商品转让是什么意思
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设