annotate 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
rev   line source
rlm@3 1 <?php
rlm@3 2 // +----------------------------------------------------------------------+
rlm@3 3 // | PHP version 5 |
rlm@3 4 // +----------------------------------------------------------------------+
rlm@3 5 // | Copyright (c) 2002-2006 James Heinrich, Allan Hansen |
rlm@3 6 // +----------------------------------------------------------------------+
rlm@3 7 // | This source file is subject to version 2 of the GPL license, |
rlm@3 8 // | that is bundled with this package in the file license.txt and is |
rlm@3 9 // | available through the world-wide-web at the following url: |
rlm@3 10 // | http://www.gnu.org/copyleft/gpl.html |
rlm@3 11 // +----------------------------------------------------------------------+
rlm@3 12 // | getID3() - http://getid3.sourceforge.net or http://www.getid3.org |
rlm@3 13 // +----------------------------------------------------------------------+
rlm@3 14 // | Authors: James Heinrich <infoØgetid3*org> |
rlm@3 15 // | Allan Hansen <ahØartemis*dk> |
rlm@3 16 // +----------------------------------------------------------------------+
rlm@3 17 // | module.lib.data-hash.php |
rlm@3 18 // | getID3() library file. |
rlm@3 19 // | dependencies: NONE. |
rlm@3 20 // +----------------------------------------------------------------------+
rlm@3 21 //
rlm@3 22 // $Id: module.lib.image_size.php,v 1.2 2006/11/02 10:48:02 ah Exp $
rlm@3 23
rlm@3 24
rlm@3 25
rlm@3 26 class getid3_lib_image_size
rlm@3 27 {
rlm@3 28
rlm@3 29 const GIF_SIG = "\x47\x49\x46"; // 'GIF'
rlm@3 30 const PNG_SIG = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
rlm@3 31 const JPG_SIG = "\xFF\xD8\xFF";
rlm@3 32 const JPG_SOS = "\xDA"; // Start Of Scan - image data start
rlm@3 33 const JPG_SOF0 = "\xC0"; // Start Of Frame N
rlm@3 34 const JPG_SOF1 = "\xC1"; // N indicates which compression process
rlm@3 35 const JPG_SOF2 = "\xC2"; // Only SOF0-SOF2 are now in common use
rlm@3 36 const JPG_SOF3 = "\xC3"; // NB: codes C4 and CC are *not* SOF markers
rlm@3 37 const JPG_SOF5 = "\xC5";
rlm@3 38 const JPG_SOF6 = "\xC6";
rlm@3 39 const JPG_SOF7 = "\xC7";
rlm@3 40 const JPG_SOF9 = "\xC9";
rlm@3 41 const JPG_SOF10 = "\xCA";
rlm@3 42 const JPG_SOF11 = "\xCB"; // NB: codes C4 and CC are *not* SOF markers
rlm@3 43 const JPG_SOF13 = "\xCD";
rlm@3 44 const JPG_SOF14 = "\xCE";
rlm@3 45 const JPG_SOF15 = "\xCF";
rlm@3 46 const JPG_EOI = "\xD9"; // End Of Image (end of datastream)
rlm@3 47
rlm@3 48
rlm@3 49 static public function get($img_data) {
rlm@3 50
rlm@3 51 $height = $width = $type = '';
rlm@3 52
rlm@3 53 if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) {
rlm@3 54
rlm@3 55 $dim = unpack('v2dim', substr($img_data, 6, 4));
rlm@3 56 $width = $dim['dim1'];
rlm@3 57 $height = $dim['dim2'];
rlm@3 58 $type = 1;
rlm@3 59
rlm@3 60 } elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) {
rlm@3 61
rlm@3 62 $dim = unpack('N2dim', substr($img_data, 16, 8));
rlm@3 63 $width = $dim['dim1'];
rlm@3 64 $height = $dim['dim2'];
rlm@3 65 $type = 3;
rlm@3 66
rlm@3 67 } elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) {
rlm@3 68
rlm@3 69 ///////////////// JPG CHUNK SCAN ////////////////////
rlm@3 70 $img_pos = $type = 2;
rlm@3 71 $buffer = strlen($img_data) - 2;
rlm@3 72 while ($img_pos < strlen($img_data)) {
rlm@3 73
rlm@3 74 // synchronize to the marker 0xFF
rlm@3 75 $img_pos = strpos($img_data, 0xFF, $img_pos) + 1;
rlm@3 76 $marker = $img_data[$img_pos];
rlm@3 77 do {
rlm@3 78 $marker = ord($img_data[$img_pos++]);
rlm@3 79 } while ($marker == 255);
rlm@3 80
rlm@3 81 // find dimensions of block
rlm@3 82 switch (chr($marker)) {
rlm@3 83
rlm@3 84 // Grab width/height from SOF segment (these are acceptable chunk types)
rlm@3 85 case getid3_lib_image_size::JPG_SOF0:
rlm@3 86 case getid3_lib_image_size::JPG_SOF1:
rlm@3 87 case getid3_lib_image_size::JPG_SOF2:
rlm@3 88 case getid3_lib_image_size::JPG_SOF3:
rlm@3 89 case getid3_lib_image_size::JPG_SOF5:
rlm@3 90 case getid3_lib_image_size::JPG_SOF6:
rlm@3 91 case getid3_lib_image_size::JPG_SOF7:
rlm@3 92 case getid3_lib_image_size::JPG_SOF9:
rlm@3 93 case getid3_lib_image_size::JPG_SOF10:
rlm@3 94 case getid3_lib_image_size::JPG_SOF11:
rlm@3 95 case getid3_lib_image_size::JPG_SOF13:
rlm@3 96 case getid3_lib_image_size::JPG_SOF14:
rlm@3 97 case getid3_lib_image_size::JPG_SOF15:
rlm@3 98 $dim = unpack('n2dim', substr($img_data, $img_pos + 3, 4));
rlm@3 99 $height = $dim['dim1'];
rlm@3 100 $width = $dim['dim2'];
rlm@3 101 break 2; // found it so exit
rlm@3 102
rlm@3 103 case getid3_lib_image_size::JPG_EOI:
rlm@3 104 case getid3_lib_image_size::JPG_SOS:
rlm@3 105 return false;
rlm@3 106
rlm@3 107 default: // We're not interested in other markers
rlm@3 108 $skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2;
rlm@3 109 // if the skip is more than what we've read in, read more
rlm@3 110 $buffer -= $skiplen;
rlm@3 111 if ($buffer < 512) { // if the buffer of data is too low, read more file.
rlm@3 112 return false;
rlm@3 113 }
rlm@3 114 $img_pos += $skiplen;
rlm@3 115 break;
rlm@3 116 }
rlm@3 117 }
rlm@3 118 }
rlm@3 119
rlm@3 120 return array ($width, $height, $type);
rlm@3 121 } // end function
rlm@3 122
rlm@3 123
rlm@3 124 }
rlm@3 125
rlm@3 126 ?>