最新下载
热门教程
- 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;
?>
相关文章
- ps怎么做光圈的光晕效果?ps照片添加唯美光晕的技巧 07-01
- 苏丹的游戏谋反线详细攻略 07-01
- 苏丹的游戏欢愉之馆全收集方式 07-01
- Hyperliquid 价格能否在 2025 年第三季度创新高 07-01
- 标普500指数上链!Centrifuge 和 S&P DJI 共同宣布「24/7交易」来了 07-01
- 金铲铲之战s14超频源计划纳亚菲利阵容攻略 07-01