最近在幫忙寫個程式,裡面有個功能需要透過PHP判斷上傳圖片的解析度(DPI),

但是找了很多種方式都不太方便,

有的甚至要另外裝元件才有功能,非常不便,

所以在別的網站搜尋到一個副程式可以使用,

經過測試是可以取得圖片的DPI,

但是詳細的判斷內容不是很理解,

該程式先開啟圖片抓取第一列的原碼再轉成16進位,

然而為何去抓取區間可以得知DPI就不曉得了~

在這裡分享給有需要的人囉!

function get_dpi($filename){  
 
    // open the file and read first 20 bytes.  
    $a = fopen($filename,'r');  
    $string = fread($a,20);  
    fclose($a);  
 
    // get the value of byte 14th up to 18th  
    $data = bin2hex(substr($string,14,4));  
    $x = substr($data,0,4);  
    $y = substr($data,4,4);  
    return array(hexdec($x),hexdec($y));  
}  
 
// output the result:  
print_r(get_dpi2('filename.jpg'));

參考網頁:

http://blog.sina.com.cn/s/blog_54b5a7e50100wup5.html

arrow
arrow

    Feng 發表在 痞客邦 留言(1) 人氣()