PHP 實(shí)現(xiàn)的將圖片轉(zhuǎn)換為TXT
PHP 實(shí)現(xiàn)的將圖片轉(zhuǎn)換為TXT
<?php /* 2015年10月19日10:24:59 */ // 打開一幅圖像 $file_name='d:\ascii_dora.png'; $chars = "$@B%8&WM#*oahkbdpqwmZO0QLCJUYXzcvunxrjft/\|()1{}[]?-_+~<>i!lI;:,\"^`'. "; function getimgchars($color_tran,$chars){ $length = strlen($chars); $alpha=$color_tran['alpha']; $r=$color_tran['red']; $g=$color_tran['green']; $b=$color_tran['blue']; $gray = intval(0.2126 * $r + 0.7152 * $g + 0.0722 * $b); if($gray==0){ return '.'; } if($gray<196){ $unit = (256.0 + 1)/$length; return $chars[intval($gray/$unit)]; } return " "; } function color_img($color_tran,$chars){ $length = strlen($chars); $alpha=$color_tran['alpha']; $r=$color_tran['red']; $g=$color_tran['green']; $b=$color_tran['blue']; $gray = intval(0.2126 * $r + 0.7152 * $g + 0.0722 * $b); $rand=rand (0, $length-1); $color="rgb(".$r.",".$g.",".$b.")"; $char=$chars[$rand]; return '<span style="color:'.$color.'" >'.$char."</span>";; } function resize_img($file_name,$chars,$flage=true){ //header('Content-Type: image/jpeg'); list($width, $height,$type) = getimagesize($file_name); $fun='imagecreatefrom' . image_type_to_extension($type, false); if($type==3){ $flage=false; } $fun($file_name); $new_height =100; $percent=$height/$new_height; $new_width=$width/$percent; $image_p = imagecreatetruecolor($new_width, $new_height); $image = $fun($file_name); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); if($flage){ return $image_p; }else{ return $image; } } $im=resize_img($file_name,$chars); $width=imagesx($im); $height=imagesy($im); $back_text=""; for($i=1;$i<=$height;$i++){ for($j=1;$j<=$width;$j++){ $color_index = imagecolorat($im, $j-1, $i-1); $color_tran = imagecolorsforindex($im, $color_index); $back_text.=color_img($color_tran,$chars,false); } $back_text.="<br/>"; } echo "<pre>"; echo $back_text; echo "</pre>"; //file_put_contents('1.txt',$back_text);
- 利用PHP將圖片轉(zhuǎn)換成base64編碼的實(shí)現(xiàn)方法
- 使用PHP+JavaScript將HTML頁面轉(zhuǎn)換為圖片的實(shí)例分享
- php將圖片文件轉(zhuǎn)換成二進(jìn)制輸出的方法
- php實(shí)現(xiàn)圖片轉(zhuǎn)換成ASCII碼的方法
- php圖片的二進(jìn)制轉(zhuǎn)換實(shí)現(xiàn)方法
- PHP把JPEG圖片轉(zhuǎn)換成Progressive JPEG的方法
- php中將圖片gif,jpg或mysql longblob或blob字段值轉(zhuǎn)換成16進(jìn)制字符串
- PHP圖片轉(zhuǎn)換通 v1.0可以將圖片轉(zhuǎn)換為php代碼的綠色軟件
- php源碼之將圖片轉(zhuǎn)化為data/base64數(shù)據(jù)流實(shí)例詳解
- PHP中使用imagick實(shí)現(xiàn)把PDF轉(zhuǎn)成圖片
- php旋轉(zhuǎn)圖片90度的方法
- PHP實(shí)現(xiàn)接收二進(jìn)制流轉(zhuǎn)換成圖片的方法
相關(guān)文章
PHP實(shí)現(xiàn)JS中escape與unescape的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)JS中escape與unescape的方法,通過json_encode和json_decode方法實(shí)現(xiàn)JS中escape與unescape函數(shù)的功能,需要的朋友可以參考下2016-07-07PHP常用字符串操作函數(shù)實(shí)例總結(jié)(trim、nl2br、addcslashes、uudecode、md5等)
這篇文章主要介紹了PHP常用字符串操作函數(shù),結(jié)合實(shí)例形式總結(jié)分析了PHP針對字符串操作的常用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-01-01判斷Keep-Alive模式的HTTP請求的結(jié)束的實(shí)現(xiàn)代碼
在使用短連接方式時(shí),每個(gè)HTTP請求對應(yīng)一個(gè)TCP連接,請求完成后連接立即斷開,服務(wù)器返回EOF。2011-08-08講解WordPress開發(fā)中一些常用的debug技巧
這篇文章主要介紹了WordPress開發(fā)中一些常用的debug技巧,需要的朋友可以參考下2015-12-12php調(diào)用方法mssql_fetch_row、mssql_fetch_array、mssql_fetch_assoc和m
mysql_fetch_object() 和 mssql_fetch_array類似,只有一點(diǎn)區(qū)別,即返回一個(gè)對象而不是數(shù)組,并將字段名字做為屬性。間接地也意味著只能通過字段名來訪問,而不是偏移量2012-08-08高并發(fā)php uniqid不重復(fù)唯一標(biāo)識符生成方案
這篇文章主要介紹了高并發(fā)php uniqid不重復(fù)唯一標(biāo)識符生成方案,對高并發(fā)感興趣的同學(xué),一定要看一下2021-04-04