Mercurial > judyates
view e2gallerypro/e2upload/Backend/Assets/getid3/module.lib.image_size.php @ 12:2f433df9b961 judyates
[svn r13] Modified esgallery source to enable multiple paypal buttons; got the photo gallery operational and tested.
author | rlm |
---|---|
date | Mon, 12 Apr 2010 03:24:08 -0400 |
parents | 3f6b44aa6b35 |
children |
line wrap: on
line source
1 <?php2 // +----------------------------------------------------------------------+3 // | PHP version 5 |4 // +----------------------------------------------------------------------+5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |6 // +----------------------------------------------------------------------+7 // | This source file is subject to version 2 of the GPL license, |8 // | that is bundled with this package in the file license.txt and is |9 // | available through the world-wide-web at the following url: |10 // | http://www.gnu.org/copyleft/gpl.html |11 // +----------------------------------------------------------------------+12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |13 // +----------------------------------------------------------------------+14 // | Authors: James Heinrich <infoØgetid3*org> |15 // | Allan Hansen <ahØartemis*dk> |16 // +----------------------------------------------------------------------+17 // | module.lib.data-hash.php |18 // | getID3() library file. |19 // | dependencies: NONE. |20 // +----------------------------------------------------------------------+21 //22 // $Id: module.lib.image_size.php,v 1.2 2006/11/02 10:48:02 ah Exp $26 class getid3_lib_image_size27 {29 const GIF_SIG = "\x47\x49\x46"; // 'GIF'30 const PNG_SIG = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";31 const JPG_SIG = "\xFF\xD8\xFF";32 const JPG_SOS = "\xDA"; // Start Of Scan - image data start33 const JPG_SOF0 = "\xC0"; // Start Of Frame N34 const JPG_SOF1 = "\xC1"; // N indicates which compression process35 const JPG_SOF2 = "\xC2"; // Only SOF0-SOF2 are now in common use36 const JPG_SOF3 = "\xC3"; // NB: codes C4 and CC are *not* SOF markers37 const JPG_SOF5 = "\xC5";38 const JPG_SOF6 = "\xC6";39 const JPG_SOF7 = "\xC7";40 const JPG_SOF9 = "\xC9";41 const JPG_SOF10 = "\xCA";42 const JPG_SOF11 = "\xCB"; // NB: codes C4 and CC are *not* SOF markers43 const JPG_SOF13 = "\xCD";44 const JPG_SOF14 = "\xCE";45 const JPG_SOF15 = "\xCF";46 const JPG_EOI = "\xD9"; // End Of Image (end of datastream)49 static public function get($img_data) {51 $height = $width = $type = '';53 if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) {55 $dim = unpack('v2dim', substr($img_data, 6, 4));56 $width = $dim['dim1'];57 $height = $dim['dim2'];58 $type = 1;60 } elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) {62 $dim = unpack('N2dim', substr($img_data, 16, 8));63 $width = $dim['dim1'];64 $height = $dim['dim2'];65 $type = 3;67 } elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) {69 ///////////////// JPG CHUNK SCAN ////////////////////70 $img_pos = $type = 2;71 $buffer = strlen($img_data) - 2;72 while ($img_pos < strlen($img_data)) {74 // synchronize to the marker 0xFF75 $img_pos = strpos($img_data, 0xFF, $img_pos) + 1;76 $marker = $img_data[$img_pos];77 do {78 $marker = ord($img_data[$img_pos++]);79 } while ($marker == 255);81 // find dimensions of block82 switch (chr($marker)) {84 // Grab width/height from SOF segment (these are acceptable chunk types)85 case getid3_lib_image_size::JPG_SOF0:86 case getid3_lib_image_size::JPG_SOF1:87 case getid3_lib_image_size::JPG_SOF2:88 case getid3_lib_image_size::JPG_SOF3:89 case getid3_lib_image_size::JPG_SOF5:90 case getid3_lib_image_size::JPG_SOF6:91 case getid3_lib_image_size::JPG_SOF7:92 case getid3_lib_image_size::JPG_SOF9:93 case getid3_lib_image_size::JPG_SOF10:94 case getid3_lib_image_size::JPG_SOF11:95 case getid3_lib_image_size::JPG_SOF13:96 case getid3_lib_image_size::JPG_SOF14:97 case getid3_lib_image_size::JPG_SOF15:98 $dim = unpack('n2dim', substr($img_data, $img_pos + 3, 4));99 $height = $dim['dim1'];100 $width = $dim['dim2'];101 break 2; // found it so exit103 case getid3_lib_image_size::JPG_EOI:104 case getid3_lib_image_size::JPG_SOS:105 return false;107 default: // We're not interested in other markers108 $skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2;109 // if the skip is more than what we've read in, read more110 $buffer -= $skiplen;111 if ($buffer < 512) { // if the buffer of data is too low, read more file.112 return false;113 }114 $img_pos += $skiplen;115 break;116 }117 }118 }120 return array ($width, $height, $type);121 } // end function124 }126 ?>