php實現圖片轉換成ASCII碼的方法_PHP教程
教程Tag:暫無Tag,歡迎添加,賺取U幣!
推薦:php解析字符串里所有URL地址的方法具體如下:
這篇文章主要介紹了php實現圖片轉換成ASCII碼的方法,涉及php操作圖片的技巧,需要的朋友可以參考下
本文實例講述了php實現圖片轉換成ASCII碼的方法。分享給大家供大家參考。具體如下:
php圖片轉換成ASCII碼,轉換后可以直接通過字符串顯示圖片
- <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>
分享:php對文件進行hash運算的方法具體如下: 這段代碼非常有用,如果你下載了一個文件,網站提供了hash結果,你可以對你下載下來的文件進行hash運算,以驗證下載的文件是否正確。
相關PHP教程:
- 相關鏈接:
- 教程說明:
PHP教程-php實現圖片轉換成ASCII碼的方法
。