src/UI/Image.php
public function load( $fileName, $tolerateAnimatedGif = FALSE )
	{
		if( !file_exists( $fileName ) )
			throw new RuntimeException( 'Image "'.$fileName.'" is not existing' );
		if( !is_readable( $fileName ) )
			throw new RuntimeException( 'Image "'.$fileName.'" is not readable' );
		$info = getimagesize( $fileName );
		if( !$info )
			throw new Exception( 'Image "'.$fileName.'" is not of a supported type' );
		if( !$tolerateAnimatedGif && self::isAnimated( $fileName ) )
			throw new RuntimeException( 'Animated GIFs are not supported' );
		if( $this->resource )
			imagedestroy( $this->resource );
		$this->type		= $info[2];
		switch( $this->type )
		{
			case IMAGETYPE_GIF:
				$resource	= imagecreatefromgif( $fileName );
				break;
			case IMAGETYPE_JPEG:
				$resource	= imagecreatefromjpeg( $fileName );
				break;
			case IMAGETYPE_PNG:
				$resource	= imagecreatefrompng( $fileName );
				break;
			default:
				throw new Exception( 'Image type "'.$info['mime'].'" is no supported, detected '.$info[2] );
		}
		$this->fileName	= $fileName;
		$this->setResource( $resource );
	}
public function load( $fileName, $tolerateAnimatedGif = FALSE )
	{
		if( !file_exists( $fileName ) )
			throw new RuntimeException( 'Image "'.$fileName.'" is not existing' );
		if( !is_readable( $fileName ) )
			throw new RuntimeException( 'Image "'.$fileName.'" is not readable' );
		$info = getimagesize( $fileName );
		if( !$info )
			throw new Exception( 'Image "'.$fileName.'" is not of a supported type' );
		if( !$tolerateAnimatedGif && self::isAnimated( $fileName ) )
			throw new RuntimeException( 'Animated GIFs are not supported' );
		if( $this->resource )
			imagedestroy( $this->resource );
		$this->type		= $info[2];
		switch( $this->type )
		{
			case IMAGETYPE_GIF:
				$resource	= imagecreatefromgif( $fileName );
				break;
			case IMAGETYPE_JPEG:
				$resource	= imagecreatefromjpeg( $fileName );
				break;
			case IMAGETYPE_PNG:
				$resource	= imagecreatefrompng( $fileName );
				break;
			default:
				throw new Exception( 'Image type "'.$info['mime'].'" is no supported, detected '.$info[2] );
		}
		$this->fileName	= $fileName;
		$this->setResource( $resource );
	}
public function load ( $ fileName , $ tolerateAnimatedGif = FALSE ) { if ( ! file_exists ( $ fileName ) ) throw new RuntimeException ( 'Image "' . $ fileName . '" is not existing' ) ; if ( ! is_readable ( $ fileName ) ) throw new RuntimeException ( 'Image "' . $ fileName . '" is not readable' ) ; $ info = getimagesize ( $ fileName ) ; if ( ! $ info ) throw new Exception ( 'Image "' . $ fileName . '" is not of a supported type' ) ; if ( ! $ tolerateAnimatedGif && self :: isAnimated ( $ fileName ) ) throw new RuntimeException ( 'Animated GIFs are not supported' ) ; if ( $ this -> resource ) imagedestroy ( $ this -> resource ) ; $ this -> type = $ info [ 2 ] ; switch ( $ this -> type ) { case IMAGETYPE_GIF : $ resource = imagecreatefromgif ( $ fileName ) ; break ; case IMAGETYPE_JPEG : $ resource = imagecreatefromjpeg ( $ fileName ) ; break ; case IMAGETYPE_PNG : $ resource = imagecreatefrompng ( $ fileName ) ; break ; default : throw new Exception ( 'Image type "' . $ info [ 'mime' ] . '" is no supported, detected ' . $ info [ 2 ] ) ; } $ this -> fileName = $ fileName ; $ this -> setResource ( $ resource ) ; }
Reads an image from file, supporting several file types.
@access		public
@param		string		$fileName		Name of image file
@return		void
@throws		RuntimeException if file is not existing
@throws		RuntimeException if file is not readable
@throws		RuntimeException if file is not a image
@throws		Exception if detected image type is not supported
@throws		Exception if image type is not supported for reading
Reads an image from file supporting several file types .