Location: PHPKode > scripts > GD Source > gd-source/GDSource.class.php
<?php
/*
 *
 * GDSource
 *
 */
Class GDSource {
	var $im = NULL;
	var $id = Array (
			"\xFF\xD8\xFF\xE0",
			"\x47\x49\x46\x38\x37\x61",
			"\x47\x49\x46\x38\x39\x61",
			"\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
	);
	/*
	 *
	 *	Main Class Constructor: GDSource
	 *
	 */
	function GDSource ( $source, $flag ) {
		if ( is_array ( $source ) ) {
			$this -> im = Array ( );

			if ( $flag == strtolower ( "url" ) ) {
				foreach ( $source as $src ) {
					if ( !$id = @fread ( fopen ( $src, "rb" ), 8 ) ) {
						print ( "File read error, script execution has stopped!" );
						exit ( 0 );
					}
					if ( substr ( $id, 0, 4 ) == $this -> id [ 0 ] ) {
						//JPG
						$this -> im [ ] = imageCreateFromJpeg ( $src );
					}
					else if ( substr ( $id, 0, 6 ) == $this -> id [ 1 ] ) {
						//GIF87a
						$this -> im [ ] = imageCreateFromGif ( $src );
					}
					else if ( substr ( $id, 0, 6 ) == $this -> id [ 2 ] ) {
						//GIF89a
						$this -> im [ ] = imageCreateFromGif ( $src );
					}
					else if ( substr ( $id, 0, 8 ) == $this -> id [ 3 ] ) {
						//PNG
						$this -> im [ ] = imageCreateFromPng ( $src );
					}
					else {
						// Unsupported
						print ( "Unsupported image format found, script execution has stopped!" );
						exit ( 0 );
					}
				}
			}
			else if ( $flag == strtolower ( "bin" ) ) {
				foreach ( $source as $src ) {
					$this -> im [ ] = imageCreateFromString ( $src );
				}
			}
			else {
				// Unknow flag
				printf ( "Unknown flag <em>%s</em>, script execution has stopped!", $flag );
				exit ( 0 );
			}
		}
		else {
			if ( $flag == strtolower ( "url" ) ) {
				if ( !@fread ( fopen ( $source, "rb" ), 8 ) ) {
					print ( "File read error, script execution has stopped!" );
					exit ( 0 );
				}
				if ( substr ( $id, 0, 4 ) == $this -> id [ 0 ] ) {
					//JPG
					$this -> im = imageCreateFromJpeg ( $source );
				}
				else if ( substr ( $id, 0, 6 ) == $this -> id [ 1 ] ) {
					//GIF87a
					$this -> im = imageCreateFromGif ( $source );
				}
				else if ( substr ( $id, 0, 6 ) == $this -> id [ 2 ] ) {
					//GIF89a
					$this -> im = imageCreateFromGif ( $source );
				}
				else if ( substr ( $id, 0, 8 ) == $this -> id [ 3 ] ) {
					//PNG
					$this -> im = imageCreateFromPng ( $source );
				}
				else {
					// Unsupported
					print ( "Unsupported image format found, script execution has stopped!" );
					exit ( 0 );
				}
			}
			else if ( $flag == strtolower ( "bin" ) ) {
				$this -> im = imageCreateFromString ( $source );
			}
			else {
				// Unknow flag
				printf ( "Unknown flag <em>%s</em>, script execution has stopped!", $flag );
				exit ( 0 );
			}
		}
	}
	/*
	 *
	 *	Public function: GetID ( )
	 *
	 */
	function GetID ( ) {
		return $this -> im;
	}
}
?>
Return current item: GD Source