php實現(xiàn)圖片轉(zhuǎn)換成ASCII碼的方法
來源:易賢網(wǎng) 閱讀:1721 次 日期:2015-04-17 09:37:17
溫馨提示:易賢網(wǎng)小編為您整理了“php實現(xiàn)圖片轉(zhuǎn)換成ASCII碼的方法”,方便廣大網(wǎng)友查閱!

具體如下:

php圖片轉(zhuǎn)換成ASCII碼,轉(zhuǎn)換后可以直接通過字符串顯示圖片

<html>

<head>

<title>Ascii</title>

<style>

body{

line-height:0;

font-size:1px;

}

</style>

</head>

<body>

<?php

$image = 'image.jpg';

// Supports http if allow_url_fopen is enabled

$image = file_get_contents($image);

$img = imagecreatefromstring($image);

$width = imagesx($img);

$height = imagesy($img);

for($h=0;$h<$height;$h++){

for($w=0;$w<=$width;$w++){

$rgb = imagecolorat($img, $w, $h);

$a = ($rgb >> 24) & 0xFF;

$r = ($rgb >> 16) & 0xFF;

$g = ($rgb >> 8) & 0xFF;

$b = $rgb & 0xFF;

$a = abs(($a / 127) - 1);

if($w == $width){

echo '<br>';

}else{

echo '<span style="color:rgba('.$r.','.$g.','.$b.','.$a.');">#</span>';

}

}

}

?>

</body>

</html>

更多信息請查看IT技術專欄

更多信息請查看網(wǎng)絡編程
易賢網(wǎng)手機網(wǎng)站地址:php實現(xiàn)圖片轉(zhuǎn)換成ASCII碼的方法
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點

版權(quán)所有:易賢網(wǎng)