热烈祝贺台州朗动科技的站长论坛隆重上线!(2012-05-28)    热烈庆祝伟大的祖国60周年生日 点击进来我们一起为她祝福吧(2009-09-26)    站长论坛禁止发布广告,一经发现立即删除。谢谢各位合作!.(2009-08-08)    热烈祝贺台州网址导航全面升级,全新版本上线!希望各位一如既往地支持台州网址导航的发展.(2009-03-28)    台州站长论坛恭祝各位新年快乐,牛年行大运!(2009-01-24)    台州Link正式更名为台州网址导航,专业做以台州网址为主的网址导航!(2008-05-23)    热烈祝贺台州Link资讯改名为中国站长资讯!希望在以后日子里得到大家的大力支持和帮助!(2008-04-10)    热烈祝贺台州Link论坛改名为台州站长论坛!希望大家继续支持和鼓励!(2008-04-10)    台州站长论坛原[社会琐碎]版块更名为[生活百科]版块!(2007-09-05)    特此通知:新台州站长论坛的数据信息全部升级成功!">特此通知:新台州站长论坛的数据信息全部升级成功!(2007-09-01)    台州站长论坛对未通过验证的会员进行合理的清除,请您谅解(2007-08-30)    台州网址导航|上网导航诚邀世界各地的网站友情链接和友谊联盟,共同引领网站导航、前进!(2007-08-30)    禁止发广告之类的帖,已发现立即删除!(2007-08-30)    希望各位上传与下载有用资源和最新信息(2007-08-30)    热烈祝贺台州站长论坛全面升级成功,全新上线!(2007-08-30)    
便民网址导航,轻松网上冲浪。
台州维博网络专业开发网站门户平台系统
您当前的位置: 首页 » PHP/Perl编程 » 得到图片的长、宽及类型

得到图片的长、宽及类型

论坛链接
  • 得到图片的长、宽及类型
  • 发布时间:2007-10-04 17:37:11    浏览数:4740    发布者:tznktg    设置字体【   
<?php
#########################################################
# #
# Release....: ImageVue.v1.4.PHP.NULL-WDYL #
# Date.......: 01/30/04 #
# Released...: WDYL #
# Protection.: CallHome, License Check, Refferer Links #
# #
#########################################################
define('GIF_SIG', chr(0x47).chr(0x49).chr(0x46)); // 'GIF'

define('PNG_SIG', chr(0x89).chr(0x50).chr(0x4E).chr(0x47).chr(0x0D).chr(0x0A).chr(0x1A).chr(0x0A));

define('JPG_SIG', chr(0xFF).chr(0xD8).chr(0xFF));
define('JPG_SOS', chr(0xDA)); // Start Of Scan - image data start
define('JPG_SOF0', chr(0xC0)); // Start Of Frame N
define('JPG_SOF1', chr(0xC1)); // N indicates which compression process
define('JPG_SOF2', chr(0xC2)); // Only SOF0-SOF2 are now in common use
define('JPG_SOF3', chr(0xC3));
// NB: codes C4 and CC are *not* SOF markers
define('JPG_SOF5', chr(0xC5));
define('JPG_SOF6', chr(0xC6));
define('JPG_SOF7', chr(0xC7));
define('JPG_SOF9', chr(0xC9));
define('JPG_SOF10', chr(0xCA));
define('JPG_SOF11', chr(0xCB));
// NB: codes C4 and CC are *not* SOF markers
define('JPG_SOF13', chr(0xCD));
define('JPG_SOF14', chr(0xCE));
define('JPG_SOF15', chr(0xCF));
define('JPG_EOI', chr(0xD9)); // End Of Image (end of datastream)


function GetURLImageSize($urlpic) {
if ($fd = @fopen($urlpic, 'rb')){
$imgData = fread($fd, filesize($urlpic));
fclose($fd);
return GetDataImageSize($imgData);
} else {
return array('', '', '');
}
}


function GetDataImageSize($imgData) {
$height = '';
$width = '';
$type = '';
if ((substr($imgData, 0, 3) == GIF_SIG) && (strlen($imgData) > 10)) {
$dim = unpack('v2dim', substr($imgData, 6, 4));
$width = $dim['dim1'];
$height = $dim['dim2'];
$type = 1;
} elseif ((substr($imgData, 0, 8) == PNG_SIG) && (strlen($imgData) > 24)) {
$dim = unpack('N2dim', substr($imgData, 16, 8));
$width = $dim['dim1'];
$height = $dim['dim2'];
$type = 3;
} elseif ((substr($imgData, 0, 3) == JPG_SIG) && (strlen($imgData) > 4)) {
///////////////// JPG CHUNK SCAN ////////////////////
$imgPos = 2;
$type = 2;
$buffer = strlen($imgData) - 2;
while ($imgPos < strlen($imgData)) {
// synchronize to the marker 0xFF
$imgPos = strpos($imgData, 0xFF, $imgPos) + 1;
$marker = $imgData[$imgPos];
do {
$marker = ord($imgData[$imgPos++]);
} while ($marker == 255);
// find dimensions of block
switch (chr($marker)) {
// Grab width/height from SOF segment (these are acceptable chunk types)
case JPG_SOF0:
case JPG_SOF1:
case JPG_SOF2:
case JPG_SOF3:
case JPG_SOF5:
case JPG_SOF6:
case JPG_SOF7:
case JPG_SOF9:
case JPG_SOF10:
case JPG_SOF11:
case JPG_SOF13:
case JPG_SOF14:
case JPG_SOF15:
$dim = unpack('n2dim', substr($imgData, $imgPos + 3, 4));
$height = $dim['dim1'];
$width = $dim['dim2'];
break 2; // found it so exit
case JPG_EOI:
case JPG_SOS:
return false; // End loop in case we find one of these markers
default: // We're not interested in other markers
$skiplen = (ord($imgData[$imgPos++]) << 8) + ord($imgData[$imgPos++]) - 2;
// if the skip is more than what we've read in, read more
$buffer -= $skiplen;
if ($buffer < 512) { // if the buffer of data is too low, read more file.
// $imgData .= fread( $fd,$skiplen+1024 );
// $buffer += $skiplen + 1024;
return false; // End loop in case we find run out of data
}
$imgPos += $skiplen;
break;
} // endswitch check marker type
} // endif loop through JPG chunks
} // endif chk for valid file types

return array($width, $height, $type);
} // end function


function ImageTypesLookup($imagetypeid) {
static $ImageTypesLookup = array();
if (empty($ImageTypesLookup)) {
$ImageTypesLookup[1] = 'gif';
$ImageTypesLookup[2] = 'jpg';
$ImageTypesLookup[3] = 'png';
$ImageTypesLookup[4] = 'swf';
$ImageTypesLookup[5] = 'psd';
$ImageTypesLookup[6] = 'bmp';
$ImageTypesLookup[7] = 'tiff (little-endian)';
$ImageTypesLookup[8] = 'tiff (big-endian)';
$ImageTypesLookup[9] = 'jpc';
$ImageTypesLookup[10] = 'jp2';
$ImageTypesLookup[11] = 'jpx';
$ImageTypesLookup[12] = 'jb2';
$ImageTypesLookup[13] = 'swc';
$ImageTypesLookup[14] = 'iff';
}
return (isset($ImageTypesLookup[$imagetypeid]) ? $ImageTypesLookup[$imagetypeid] : '');
}

?>
娱乐休闲专区A 影视预告B 音乐咖啡C 英语阶梯D 生活百科
网页编程专区E AMPZF HTMLG CSSH JSI ASPJ PHPK JSPL MySQLM AJAX
Linux技术区 N 系统管理O 服务器架设P 网络/硬件Q 编程序开发R 内核/嵌入
管理中心专区S 发布网址T 版主议事U 事务处理