Convert a php image to an ascii output image. Php image to ascii output image this PHP function creates a simple JPG image ASCII art rendering. It uses Guangdong for heavy work and converts php images into ascii output images.
Convert a php image to an ascii output image
This PHP function creates a simple JPG image ASCII art rendering. It uses Guangdong for heavy work, and some simple shift distribution colors. The color is then transferred to the hexadecimal value and the generated text is output to the browser. ASCII code from Image Art to PHP now, it's easy. If you think you have any improvement, please feel free to contact us for your idea PHPRO.
Function image2ascii ($ image)
{
// Return value
$ Ret = '';
// Open the image
$ Img = ImageCreateFromJpeg ($ image );
// Get width and height
$ Width = imagesx ($ img );
$ Height = imagesy ($ img );
// Loop for height
For ($ h = 0; $ h <$ height; $ h ++)
{
// Loop for height
For ($ w = 0; $ w <= $ width; $ w ++)
{
// Add color
$ Rgb = ImageColorAt ($ img, $ w, $ h );
$ R = ($ rgb> 16) & 0xFF;
$ G = ($ rgb> 8) & 0xFF;
$ B = $ rgb & 0xFF;
// Create a hex value from the rgb
$ Hex = '#'. str_pad (dechex ($ r), 2, '0', STR_PAD_LEFT ). str_pad (dechex ($ g), 2, '0', STR_PAD_LEFT ). str_pad (dechex ($ B), 2, '0', STR_PAD_LEFT );
// Now add to the return string and we are done
If ($ w = $ width)
{
$ Ret. ='
';
}
Else
{
$ Ret. = '#';
}
}
}
Return $ ret;
}
?>
Example Usage
// An image to convert
$ Image = 'test.jpg ';
// Do the conversion
$ Ascii = image2ascii ($ image );
// And show the world
Echo $ ascii;
?>
Http://www.bkjia.com/PHPjc/444992.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/444992.htmlTechArticlephp image converted to ascii output image php image converted to ascii output image this PHP function creates a simple JPG image ASCII art rendering. It uses Guangdong for heavy work, and...