最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 图片转换成ascii 输出图像
时间:2022-07-02 09:26:34 编辑:袖梨 来源:一聚教程网
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;
?>
相关文章
- Win11图片不显示缩略图怎么办?Win11图片不显示缩略图的解决方法 07-12
- PS详细解析人像精修后期处理技巧教程 07-12
- 无畏契约源能行动霰弹枪强度排名 霰弹枪排行介绍 07-12
- 分析师展示:牛市结束前的长期走势图会是什么样子 07-12
- dw中水平线的颜色怎么改? Dreamweaver水平线修改颜色的两种方法 07-12
- 原神伊涅芙技能是什么 伊涅芙技能一览 07-12