Code Search for Developers
 
 
  

module.lib.image_size.php from ECP (EliteCore Project) at Krugle


Show module.lib.image_size.php syntax highlighted

<?php
// +----------------------------------------------------------------------+
// | PHP version 5                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 2002-2004 James Heinrich                               |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2 of the GPL license,         |
// | that is bundled with this package in the file license.txt and is     |
// | available through the world-wide-web at the following url:           |
// | http://www.gnu.org/copyleft/gpl.html                                 |
// +----------------------------------------------------------------------+
// | getID3() - http://getid3.sourceforge.net or http://www.getid3.org    |
// +----------------------------------------------------------------------+
// | Authors: James Heinrich <infoØgetid3*org>                            |
// |          Allan Hansen <ahØartemis*dk>                                |
// +----------------------------------------------------------------------+
// | module.lib.data-hash.php                                             |
// | getID3() library file.                                               |
// | dependencies: NONE.                                                  |
// +----------------------------------------------------------------------+
//
// $Id: module.lib.image_size.php,v 1.1.1.1 2004/08/23 00:01:25 ah Exp $



class getid3_lib_image_size
{
    
    const GIF_SIG   = "\x47\x49\x46";                           // 'GIF'
    const PNG_SIG   = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
    const JPG_SIG   = "\xFF\xD8\xFF";
    const JPG_SOS   = "\xDA";                                   // Start Of Scan - image data start
    const JPG_SOF0  = "\xC0";                                   // Start Of Frame N
    const JPG_SOF1  = "\xC1";                                   // N indicates which compression process
    const JPG_SOF2  = "\xC2";                                   // Only SOF0-SOF2 are now in common use
    const JPG_SOF3  = "\xC3";                                   // NB: codes C4 and CC are *not* SOF markers
    const JPG_SOF5  = "\xC5";                                   
    const JPG_SOF6  = "\xC6";                                   
    const JPG_SOF7  = "\xC7";                                   
    const JPG_SOF9  = "\xC9";                                   
    const JPG_SOF10 = "\xCA";                                   
    const JPG_SOF11 = "\xCB";                                   // NB: codes C4 and CC are *not* SOF markers
    const JPG_SOF13 = "\xCD";                                   
    const JPG_SOF14 = "\xCE";                                   
    const JPG_SOF15 = "\xCF";                                   
    const JPG_EOI   = "\xD9";                                   // End Of Image (end of datastream)


    static public function get($img_data) {

        $height = $width  = $type   = '';
        
        if ((substr($img_data, 0, 3) == getid3_lib_image_size::GIF_SIG) && (strlen($img_data) > 10)) {
            
            $dim = unpack('v2dim', substr($img_data, 6, 4));
            $width  = $dim['dim1'];
            $height = $dim['dim2'];
            $type = 1;
            
        } elseif ((substr($img_data, 0, 8) == getid3_lib_image_size::PNG_SIG) && (strlen($img_data) > 24)) {
            
            $dim = unpack('N2dim', substr($img_data, 16, 8));
            $width  = $dim['dim1'];
            $height = $dim['dim2'];
            $type = 3;
            
        } elseif ((substr($img_data, 0, 3) == getid3_lib_image_size::JPG_SIG) && (strlen($img_data) > 4)) {
            
            ///////////////// JPG CHUNK SCAN ////////////////////
            $img_pos = $type = 2;
            $buffer = strlen($img_data) - 2;
            while ($img_pos < strlen($img_data)) {
            
                // synchronize to the marker 0xFF
                $img_pos = strpos($img_data, 0xFF, $img_pos) + 1;
                $marker = $img_data[$img_pos];
                do {
                    $marker = ord($img_data[$img_pos++]);
                } while ($marker == 255);
            
                // find dimensions of block
                switch (chr($marker)) {
            
                    // Grab width/height from SOF segment (these are acceptable chunk types)
                    case getid3_lib_image_size::JPG_SOF0:
                    case getid3_lib_image_size::JPG_SOF1:
                    case getid3_lib_image_size::JPG_SOF2:
                    case getid3_lib_image_size::JPG_SOF3:
                    case getid3_lib_image_size::JPG_SOF5:
                    case getid3_lib_image_size::JPG_SOF6:
                    case getid3_lib_image_size::JPG_SOF7:
                    case getid3_lib_image_size::JPG_SOF9:
                    case getid3_lib_image_size::JPG_SOF10:
                    case getid3_lib_image_size::JPG_SOF11:
                    case getid3_lib_image_size::JPG_SOF13:
                    case getid3_lib_image_size::JPG_SOF14:
                    case getid3_lib_image_size::JPG_SOF15:
                        $dim = unpack('n2dim', substr($img_data, $img_pos + 3, 4));
                        $height = $dim['dim1'];
                        $width  = $dim['dim2'];
                        break 2; // found it so exit
            
                    case getid3_lib_image_size::JPG_EOI:
                    case getid3_lib_image_size::JPG_SOS:
                        return false;      
            
                    default:   // We're not interested in other markers
                        $skiplen = (ord($img_data[$img_pos++]) << 8) + ord($img_data[$img_pos++]) - 2;
                        // if the skip is more than what we've read in, read more
                        $buffer -= $skiplen;
                        if ($buffer < 512) { // if the buffer of data is too low, read more file.
                            return false; 
                        }
                        $img_pos += $skiplen;
                        break;
                } 
            } 
        } 

        return array ($width, $height, $type);
    } // end function


}

?>



See more files for this project here

ECP (EliteCore Project)

EliteCore Project is a PHP5.1/Javascript/AJAX/XHTML/CSS framework for creating WEB 2.0 applications and services.The basic open-source instalation can be also used as an interactive personal page or BLOG.This project uses the latest features available.

Project homepage: http://sourceforge.net/projects/elitecore
Programming language(s): JavaScript,PHP,XML
License: cpl

  extension.cache.dbm.php
  extension.cache.mysql.php
  getid3.php
  module.archive.gzip.php
  module.archive.szip.php
  module.archive.tar.php
  module.archive.zip.php
  module.audio-video.asf.php
  module.audio-video.flv.php
  module.audio-video.mpeg.php
  module.audio-video.nsv.php
  module.audio-video.quicktime.php
  module.audio-video.real.php
  module.audio-video.riff.php
  module.audio-video.swf.php
  module.audio.aac_adif.php
  module.audio.aac_adts.php
  module.audio.ac3.php
  module.audio.au.php
  module.audio.avr.php
  module.audio.bonk.php
  module.audio.la.php
  module.audio.lpac.php
  module.audio.midi.php
  module.audio.monkey.php
  module.audio.mp3.php
  module.audio.mpc.php
  module.audio.mpc_old.php
  module.audio.optimfrog.php
  module.audio.rkau.php
  module.audio.shorten.php
  module.audio.tta.php
  module.audio.voc.php
  module.audio.vqf.php
  module.audio.wavpack.php
  module.audio.xiph.php
  module.graphic.bmp.php
  module.graphic.gif.php
  module.graphic.jpeg.php
  module.graphic.pcd.php
  module.graphic.png.php
  module.graphic.tiff.php
  module.lib.data_hash.php
  module.lib.iconv_replacement.php
  module.lib.image_size.php
  module.misc.iso.php
  module.tag.apetag.php
  module.tag.id3v1.php
  module.tag.id3v2.php
  module.tag.lyrics3.php