喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 发现一个好东西,拿出来与大家共享。  
 
jxxysong (jxxysong)
高级会员
Rank: 4
高级会员



UID 12761
精华 0
积分 902
帖子 910
金钱 902 喜悦币
威望 0
人脉 0
阅读权限 50
注册 2002-2-10
状态 离线
发现一个好东西,拿出来与大家共享。

发现一个好东西,拿出来与大家共享。

功能:得到图片的长、宽及类型。

<?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($fdfilesize($urlpic));
                
fclose($fd);
                return 
GetDataImageSize($imgData);
        } else {
                return array(
'''''');
        }
}


function 
GetDataImageSize($imgData) {
        
$height '';
        
$width  '';
        
$type   '';
        if ((
substr($imgData03) == GIF_SIG) && (strlen($imgData) > 10)) {
                
$dim unpack('v2dim'substr($imgData64));
                
$width  $dim['dim1'];
                
$height $dim['dim2'];
                
$type 1;
        } elseif ((
substr($imgData08) == PNG_SIG) && (strlen($imgData) > 24)) {
                
$dim unpack('N2dim'substr($imgData168));
                
$width  $dim['dim1'];
                
$height $dim['dim2'];
                
$type 3;
        } elseif ((
substr($imgData03) == 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($imgData0xFF$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 34));
                                        
$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] : '');
}

?>
2004-7-28 08:45 AM#1
查看资料  访问主页  发短消息  QQ . .   顶部
 
heimayi (heimayi)
金牌会员
Rank: 6Rank: 6
高级会员



UID 11687
精华 2
积分 1619
帖子 1581
金钱 1599 喜悦币
威望 20
人脉 0
阅读权限 70
注册 2002-1-4
状态 离线
[推荐阅读] 怎么通过php来查看文件的权限?
好。。。。
2004-7-28 09:10 AM#2
查看资料  发短消息  顶部
 
yhlong (yhlong)
金牌会员
Rank: 6Rank: 6
高级会员



UID 10030
精华 3
积分 1400
帖子 1338
金钱 1370 喜悦币
威望 30
人脉 0
阅读权限 70
注册 2001-11-2
来自 山东烟台
状态 离线
[推荐阅读] 关于域名范解析的问题
好的,支持!
2004-7-28 09:20 AM#3
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.044843 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP