Home > php教程 > php手册 > body text

php获取图片尺寸(宽度,高度)

WBOY
Release: 2016-06-21 08:47:24
Original
1934 people have browsed it

本篇文章主要说明PHP获取图片尺寸(宽度,高度)的函数,即getimagesize()函数。

语法:array getimagesize( string filename [, array &imageinfo] )

功能:getimagesize()函数将测定任何GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM或WBMP图像文件并返回文件的大小,尺寸,文件类型以及一个可以用于普通HTML文件中php获取图片尺寸(宽度,高度)标记中的 height/width 文本字符串。如果不能访问指定的图像或者其不是有效的图像,getimagesize()将返回FALSE并产生一条E_WARNING级的错误。

注:

(1)本函数不需要 GD 图像库支持。

(2)该函数除了可以获取本地图片或者Flash的相关信息外还可以直接用来获取远程的。

示例:

<?php
list($width,$height,$type,$attr)=getimagesize("http://www.Alixixi.com/images/logo.gif");
echo "Image width ".$width;
echo "<br/>";
echo "Image height ".$height;
echo "<br/>";
echo "Image type ".$type;
echo "<br/>";
echo "Attribute ".$attr;
Copy after login

输出信息如下:

Image width 200
 
Image height 55
 
Image type 1
 
Image attribute width="200" height="55"

其中图片类型的参数参考如下:
 
1 = GIF  5 = PSD  9 = JPC  13 = SWC
 
2 = JPG  6 = BMP  10 = JP2  14 = IFF
 
3 = PNG  7 = TIFF(intel byte order)  11 = JPX  15 = WBMP
 
4 = SWF  8 = TIFF(motorola byte order)  12 = JB2  16 = XBM

您可能感兴趣的文章

  • php获取客户端电脑屏幕宽度,高度,分辨率的方法
  • Js地址栏特效(显示页面内所有加链接的图片的大小和查看当前的浏览器的高度)
  • javascript获取图片的宽度和高度的一种方法
  • 强大的PHP 图片处理类(水印、透明度、缩放、锐化、旋转、翻转、剪切、反色)
  • php获取远程图片并下载保存到本地
  • PHP如何判断一个gif图片是否为动态图片(动画)
  • 文本区域textarea框根据输入内容自适应高度
  • 用PHP函数memory_get_usage获取当前PHP内存消耗量以实现程序的性能优化



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!