当前位置:Gxlcms > PHP教程 > php图片转换成ascii输出图像_PHP教程

php图片转换成ascii输出图像_PHP教程

时间:2021-07-01 10:21:17 帮助过:3人阅读

php 图片转换成ascii 输出图像

php 图片转换成ascii 输出图像

这个PHP函数创建了一个简单的JPG图像ASCII艺术渲染。它使用广东做繁重的工作,和一些简单的移位分配色彩。颜色,然后转移到十六进制值和生成的文本输出到浏览器。 ASCII码从影像艺术与PHP现在,很容易。如果你觉得你有什么改进,请随时与我们联系,您的想法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;
?>


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/444992.htmlTechArticlephp 图片转换成ascii 输出图像 php 图片转换成ascii 输出图像 这个PHP函数创建了一个简单的JPG图像ASCII艺术渲染。它使用广东做繁重的工作,和...

人气教程排行