JPG轉成ASCII的php代碼
將一張JPG圖像轉換成ASCII碼。
<html> <head> <title>Ascii</title> <style> body{ line-height:1px; font-size:1px; } </style> </head> <body> <?php
function getext($filename) {
$pos = strrpos($filename,'.');
$str = substr($filename, $pos);
return $str;
}
$image = 'image.jpg'; $ext = getext($image);
if($ext == ".jpg"){
$img = ImageCreateFromJpeg($image);
}
else{
echo'Wrong File Type';
}
$width = imagesx($img);
$height = imagesy($img);for($h=0;$h<$height;$h++){
for($w=0;$w<=$width;$w++){
$rgb = ImageColorAt($img, $w, $h);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;
if($w == $width){
echo '<br>';
}else{
echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>'; }
}
}
?> </body> </html></pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!