Mercurial > judyates
diff e2gallerypro/e2upload/Backend/Assets/getid3/module.lib.image_size.php @ 3:3f6b44aa6b35 judyates
[svn r4] added ability to buy stuff, from a Prints page, but it doesn't work well with the css, and it also has not been fitted into the perl make system.
author | rlm |
---|---|
date | Mon, 22 Feb 2010 08:02:39 -0500 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/e2gallerypro/e2upload/Backend/Assets/getid3/module.lib.image_size.php Mon Feb 22 08:02:39 2010 -0500 1.3 @@ -0,0 +1,126 @@ 1.4 +<?php 1.5 +// +----------------------------------------------------------------------+ 1.6 +// | PHP version 5 | 1.7 +// +----------------------------------------------------------------------+ 1.8 +// | Copyright (c) 2002-2006 James Heinrich, Allan Hansen | 1.9 +// +----------------------------------------------------------------------+ 1.10 +// | This source file is subject to version 2 of the GPL license, | 1.11 +// | that is bundled with this package in the file license.txt and is | 1.12 +// | available through the world-wide-web at the following url: | 1.13 +// | http://www.gnu.org/copyleft/gpl.html | 1.14 +// +----------------------------------------------------------------------+ 1.15 +// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org | 1.16 +// +----------------------------------------------------------------------+ 1.17 +// | Authors: James Heinrich <infoØgetid3*org> | 1.18 +// | Allan Hansen <ahØartemis*dk> | 1.19 +// +----------------------------------------------------------------------+ 1.20 +// | module.lib.data-hash.php | 1.21 +// | getID3() library file. | 1.22 +// | dependencies: NONE. | 1.23 +// +----------------------------------------------------------------------+ 1.24 +// 1.25 +// $Id: module.lib.image_size.php,v 1.2 2006/11/02 10:48:02 ah Exp $ 1.26 + 1.27 + 1.28 + 1.29 +class getid3_lib_image_size 1.30 +{ 1.31 + 1.32 + const GIF_SIG = "\x47\x49\x46"; // 'GIF' 1.33 + const PNG_SIG = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"; 1.34 + const JPG_SIG = "\xFF\xD8\xFF"; 1.35 + const JPG_SOS = "\xDA"; // Start Of Scan - image data start 1.36 + const JPG_SOF0 = "\xC0"; // Start Of Frame N 1.37 + const JPG_SOF1 = "\xC1"; // N indicates which compression process 1.38 + const JPG_SOF2 = "\xC2"; // Only SOF0-SOF2 are now in common use 1.39 + const JPG_SOF3 = "\xC3"; // NB: codes C4 and CC are *not* SOF markers 1.40 + const JPG_SOF5 = "\xC5"; 1.41 + const JPG_SOF6 = "\xC6"; 1.42 + const JPG_SOF7 = "\xC7"; 1.43 + const JPG_SOF9 = "\xC9"; 1.44 + const JPG_SOF10 = "\xCA"; 1.45 + const JPG_SOF11 = "\xCB"; // NB: codes C4 and CC are *not* SOF markers 1.46 + const JPG_SOF13 = "\xCD"; 1.47 + const JPG_SOF14 = "\xCE"; 1.48 + const JPG_SOF15 = "\xCF"; 1.49 + const JPG_EOI = "\xD9"; // End Of Image (end of datastream) 1.50 + 1.51 + 1.52 + static public function get($img_data) { 1.53 + 1.54 + $height = $width = $type = ''; 1.55 + 1.56 + if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) { 1.57 + 1.58 + $dim = unpack('v2dim', substr($img_data, 6, 4)); 1.59 + $width = $dim['dim1']; 1.60 + $height = $dim['dim2']; 1.61 + $type = 1; 1.62 + 1.63 + } elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) { 1.64 + 1.65 + $dim = unpack('N2dim', substr($img_data, 16, 8)); 1.66 + $width = $dim['dim1']; 1.67 + $height = $dim['dim2']; 1.68 + $type = 3; 1.69 + 1.70 + } elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) { 1.71 + 1.72 + ///////////////// JPG CHUNK SCAN //////////////////// 1.73 + $img_pos = $type = 2; 1.74 + $buffer = strlen($img_data) - 2; 1.75 + while ($img_pos < strlen($img_data)) { 1.76 + 1.77 + // synchronize to the marker 0xFF 1.78 + $img_pos = strpos($img_data, 0xFF, $img_pos) + 1; 1.79 + $marker = $img_data[$img_pos]; 1.80 + do { 1.81 + $marker = ord($img_data[$img_pos++]); 1.82 + } while ($marker == 255); 1.83 + 1.84 + // find dimensions of block 1.85 + switch (chr($marker)) { 1.86 + 1.87 + // Grab width/height from SOF segment (these are acceptable chunk types) 1.88 + case getid3_lib_image_size::JPG_SOF0: 1.89 + case getid3_lib_image_size::JPG_SOF1: 1.90 + case getid3_lib_image_size::JPG_SOF2: 1.91 + case getid3_lib_image_size::JPG_SOF3: 1.92 + case getid3_lib_image_size::JPG_SOF5: 1.93 + case getid3_lib_image_size::JPG_SOF6: 1.94 + case getid3_lib_image_size::JPG_SOF7: 1.95 + case getid3_lib_image_size::JPG_SOF9: 1.96 + case getid3_lib_image_size::JPG_SOF10: 1.97 + case getid3_lib_image_size::JPG_SOF11: 1.98 + case getid3_lib_image_size::JPG_SOF13: 1.99 + case getid3_lib_image_size::JPG_SOF14: 1.100 + case getid3_lib_image_size::JPG_SOF15: 1.101 + $dim = unpack('n2dim', substr($img_data, $img_pos + 3, 4)); 1.102 + $height = $dim['dim1']; 1.103 + $width = $dim['dim2']; 1.104 + break 2; // found it so exit 1.105 + 1.106 + case getid3_lib_image_size::JPG_EOI: 1.107 + case getid3_lib_image_size::JPG_SOS: 1.108 + return false; 1.109 + 1.110 + default: // We're not interested in other markers 1.111 + $skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2; 1.112 + // if the skip is more than what we've read in, read more 1.113 + $buffer -= $skiplen; 1.114 + if ($buffer < 512) { // if the buffer of data is too low, read more file. 1.115 + return false; 1.116 + } 1.117 + $img_pos += $skiplen; 1.118 + break; 1.119 + } 1.120 + } 1.121 + } 1.122 + 1.123 + return array ($width, $height, $type); 1.124 + } // end function 1.125 + 1.126 + 1.127 +} 1.128 + 1.129 +?> 1.130 \ No newline at end of file