protected function _getImageData( $code, &$mime )
	{
		$list = str_split( ltrim( $code, '#' ), 2 );

		if( count( $list ) !== 3 ) {
			throw new Exception( sprintf( 'Invalid color code "%1$s"', $code ) );
		}

		if( ( $img = imagecreate( 1, 1 ) ) === false ) {
			throw new Exception( 'Unable to create image' );
		}

		if( imagecolorallocate( $img, hexdec( $list[0] ), hexdec( $list[1] ), hexdec( $list[2] ) ) === false ) {
			throw new Exception( 'Unable to allocate color' );
		}

		try
		{
			ob_start();

			if( function_exists( 'imagegif' ) === true && imagegif( $img ) === true ) {
				$mime = 'image/gif';
			} else if( function_exists( 'imagepng' ) === true && imagepng( $img ) === true ) {
				$mime = 'image/png';
			} else {
				throw new Exception( 'Unable to create image. php-gd not installed?' );
			}

			$image = ob_get_contents();
			ob_end_clean();
		}
		catch( Exception $e )
		{
			ob_end_clean();
			throw $e;
		}

		if( imagedestroy( $img ) === false ) {
			throw new Exception( 'Unable to destroy image' );
		}

		return 'data:' . $mime . ';base64,' . base64_encode( $image );
	}
protected function _getImageData( $code, &$mime )
	{
		$list = str_split( ltrim( $code, '#' ), 2 );

		if( count( $list ) !== 3 ) {
			throw new Exception( sprintf( 'Invalid color code "%1$s"', $code ) );
		}

		if( ( $img = imagecreate( 1, 1 ) ) === false ) {
			throw new Exception( 'Unable to create image' );
		}

		if( imagecolorallocate( $img, hexdec( $list[0] ), hexdec( $list[1] ), hexdec( $list[2] ) ) === false ) {
			throw new Exception( 'Unable to allocate color' );
		}

		try
		{
			ob_start();

			if( function_exists( 'imagegif' ) === true && imagegif( $img ) === true ) {
				$mime = 'image/gif';
			} else if( function_exists( 'imagepng' ) === true && imagepng( $img ) === true ) {
				$mime = 'image/png';
			} else {
				throw new Exception( 'Unable to create image. php-gd not installed?' );
			}

			$image = ob_get_contents();
			ob_end_clean();
		}
		catch( Exception $e )
		{
			ob_end_clean();
			throw $e;
		}

		if( imagedestroy( $img ) === false ) {
			throw new Exception( 'Unable to destroy image' );
		}

		return 'data:' . $mime . ';base64,' . base64_encode( $image );
	}
protected function _getImageData ( $ code , & $ mime ) { $ list = str_split ( ltrim ( $ code , '#' ) , 2 ) ; if ( count ( $ list ) !== 3 ) { throw new Exception ( sprintf ( 'Invalid color code "%1$s"' , $ code ) ) ; } if ( ( $ img = imagecreate ( 1 , 1 ) ) === false ) { throw new Exception ( 'Unable to create image' ) ; } if ( imagecolorallocate ( $ img , hexdec ( $ list [ 0 ] ) , hexdec ( $ list [ 1 ] ) , hexdec ( $ list [ 2 ] ) ) === false ) { throw new Exception ( 'Unable to allocate color' ) ; } try { ob_start ( ) ; if ( function_exists ( 'imagegif' ) === true && imagegif ( $ img ) === true ) { $ mime = 'image/gif' ; } else if ( function_exists ( 'imagepng' ) === true && imagepng ( $ img ) === true ) { $ mime = 'image/png' ; } else { throw new Exception ( 'Unable to create image. php-gd not installed?' ) ; } $ image = ob_get_contents ( ) ; ob_end_clean ( ) ; } catch ( Exception $ e ) { ob_end_clean ( ) ; throw $ e ; } if ( imagedestroy ( $ img ) === false ) { throw new Exception ( 'Unable to destroy image' ) ; } return 'data:' . $ mime . ';base64,' . base64_encode ( $ image ) ; }
Returns the base64 encoded image data for the given color code.

@param string $code Color code in hex notation, e.g. "#000000"
@param string &$mime Contains the mime type of the created image as result
@throws Exception If the image couldn't be created
Returns the base64 encoded image data for the given color code .