Home >Backend Development >PHP Tutorial >Convert php images to ascii output images_PHP tutorial
php Convert image to ascii Output image
php Convert image to ascii Output image
This PHP function creates a simple ASCII artistic rendering of a JPG image. It uses Guangdong to do the heavy lifting, and some simple shifting to assign colors. The color is then transferred to a hexadecimal value and the resulting text is output to the browser. ASCII from Image Arts with PHP is now easy. If you feel you have any improvements, please feel free to contact us with your ideas for 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++)
= ($rgb >> 16) & 0xFF; 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)
🎜> . '; 🎜>
// an image to convert
// do the conversion
$ascii = image2ascii( $ image );
// and show the world
echo $ascii;
?>
http://www.bkjia.com/PHPjc/444992.html
TechArticle
php Convert image to ascii Output image php Convert image to ascii Output image This PHP function creates a simple JPG image ASCII artistic rendering. It uses Canton to do the heavy lifting, and...