有没针对 fopen 打开的图片文件获取信息的函数 getimagesize() 的传参是图片文件路劲如果我只知道 tmpfile() 或 fopen() 返回的文件句柄怎么办呢难道非要临时保存一下到硬盘上? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 最好保存一下,如果不使用GD函数的话,那就复杂了,要自己解析图片二进制数据来得到他的原数据了。比如这个解析png图片的。/************************* png ****************************/function _parsepng($file) { //Extract info from a PNG file $f=fopen($file,'rb'); if(!$f) $this->Error('Can\'t open image file: '.$file); //Check signature if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10)) $this->Error('Not a PNG file: '.$file); //Read header chunk fread($f,4); if(fread($f,4)!='IHDR') $this->Error('Incorrect PNG file: '.$file); $w=$this->_freadint($f); $h=$this->_freadint($f); $bpc=ord(fread($f,1)); if($bpc>8) $this->Error('16-bit depth not supported: '.$file); $ct=ord(fread($f,1)); if($ct==0) $colspace='DeviceGray'; elseif($ct==2) $colspace='DeviceRGB'; elseif($ct==3) $colspace='Indexed'; else $this->Error('Alpha channel not supported: '.$file); if(ord(fread($f,1))!=0) $this->Error('Unknown compression method: '.$file); if(ord(fread($f,1))!=0) $this->Error('Unknown filter method: '.$file); if(ord(fread($f,1))!=0) $this->Error('Interlacing not supported: '.$file); fread($f,4); $parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>'; //Scan chunks looking for palette, transparency and image data $pal=''; $trns=''; $data=''; do { $n=$this->_freadint($f); $type=fread($f,4); if($type=='PLTE') { //Read palette $pal=fread($f,$n); fread($f,4); } elseif($type=='tRNS') { //Read transparency info $t=fread($f,$n); if($ct==0) $trns=array(ord(substr($t,1,1))); elseif($ct==2) $trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1))); else { $pos=strpos($t,chr(0)); if($pos!==false) $trns=array($pos); } fread($f,4); } elseif($type=='IDAT') { //Read image data block $data.=fread($f,$n); fread($f,4); } elseif($type=='IEND') break; else fread($f,$n+4); } while($n); if($colspace=='Indexed' && empty($pal)) $this->Error('Missing palette in '.$file); fclose($f); return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data); } 哪个 _freadint() 方法是干什么用的 我想跟据按二个按钮的 AJAX反回的值,把ajax.html 的 [OK] 按钮可用或不可用[二] 正则表达式,字符串前不包括 某特定字符 PHP生成静态页面没有权限 关于php配置的问题,急 php怎么使用串口收发指令? 数组问题??? 如何使php asp能读对方的Session? 看看这个问题! php session_id用法,请指点。~ wampserver图标是绿色的,但是服务器离线 求一个PHP分页显示图片的代码 关于PHP安装VLD查看opcode
比如这个解析png图片的。/************************* png ****************************/function _parsepng($file)
{
//Extract info from a PNG file
$f=fopen($file,'rb');
if(!$f)
$this->Error('Can\'t open image file: '.$file);
//Check signature
if(fread($f,8)!=chr(137).'PNG'.chr(13).chr(10).chr(26).chr(10))
$this->Error('Not a PNG file: '.$file);
//Read header chunk
fread($f,4);
if(fread($f,4)!='IHDR')
$this->Error('Incorrect PNG file: '.$file);
$w=$this->_freadint($f);
$h=$this->_freadint($f);
$bpc=ord(fread($f,1));
if($bpc>8)
$this->Error('16-bit depth not supported: '.$file);
$ct=ord(fread($f,1));
if($ct==0)
$colspace='DeviceGray';
elseif($ct==2)
$colspace='DeviceRGB';
elseif($ct==3)
$colspace='Indexed';
else
$this->Error('Alpha channel not supported: '.$file);
if(ord(fread($f,1))!=0)
$this->Error('Unknown compression method: '.$file);
if(ord(fread($f,1))!=0)
$this->Error('Unknown filter method: '.$file);
if(ord(fread($f,1))!=0)
$this->Error('Interlacing not supported: '.$file);
fread($f,4);
$parms='/DecodeParms <</Predictor 15 /Colors '.($ct==2 ? 3 : 1).' /BitsPerComponent '.$bpc.' /Columns '.$w.'>>';
//Scan chunks looking for palette, transparency and image data
$pal='';
$trns='';
$data='';
do
{
$n=$this->_freadint($f);
$type=fread($f,4);
if($type=='PLTE')
{
//Read palette
$pal=fread($f,$n);
fread($f,4);
}
elseif($type=='tRNS')
{
//Read transparency info
$t=fread($f,$n);
if($ct==0)
$trns=array(ord(substr($t,1,1)));
elseif($ct==2)
$trns=array(ord(substr($t,1,1)),ord(substr($t,3,1)),ord(substr($t,5,1)));
else
{
$pos=strpos($t,chr(0));
if($pos!==false)
$trns=array($pos);
}
fread($f,4);
}
elseif($type=='IDAT')
{
//Read image data block
$data.=fread($f,$n);
fread($f,4);
}
elseif($type=='IEND')
break;
else
fread($f,$n+4);
}
while($n);
if($colspace=='Indexed' && empty($pal))
$this->Error('Missing palette in '.$file);
fclose($f);
return array('w'=>$w,'h'=>$h,'cs'=>$colspace,'bpc'=>$bpc,'f'=>'FlateDecode','parms'=>$parms,'pal'=>$pal,'trns'=>$trns,'data'=>$data);
}