搜尋
首頁php教程php手册PHP代码实例:图片转成HTML

PHP的

 

body{}

a{display: inline-block;width:1px;height:1px;}

function createImFromFile($path){

if(!is_file($path)){

throw new Exception("File: $path not found!");

}

$info = getimagesize($path);

switch ($info[2]){

case 1:

//gif

$tim = imagecreatefromgif($path);

$w = imagesx($tim);

$h = imagesy($tim);

$im = imagecreatetruecolor( $w,$h );

imagecopy($im,$tim,0,0,0,0,$w,$h);

imagedestroy($tim);

break;

case 2:

//jpg

$im = imagecreatefromjpeg($path);

break;

case 3:

//png

$im = imagecreatefrompng($path);

break;

default:

throw new Exception("Not support file type.File:$path");

}

return $im;

}

 

$im = createImFromFile("d:\\aa.jpg");

$w = imagesx($im);

$h = imagesy($im);

$str = "

";

for($i = 0; $i

$str .= "

";

for($j = 0; $j

$rgb = str_pad(dechex(imagecolorat($im, $j, $i)), 6, "0", STR_PAD_LEFT);

$str .="";

}

$str .= "

";

}

$str .= "

";

imagedestroy($im);

echo $str;

/*$rgb = ImageColorAt($im, 100, 100);

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

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

$b = $rgb & 0xFF;*/

?>

 

 

 

.NET 的:

 

    protected string tmp = "";

 

    protected void Page_Load(object sender , EventArgs e) {

        Bitmap bm = new Bitmap("d:\\aa.jpg");

        int w = bm.Width;

        int h = bm.Height;

        StringBuilder sb = new StringBuilder();

        Color c;

        sb.Append("

");

        for( int i = 0 ; i

            sb.Append("

");

            for( int j = 0 ; j

                c = bm.GetPixel(j,i);

                sb.Append(string.Format("" , V(c.R) , V( c.G) , V(c.B)));

            }

            sb.Append("

");

        }

        sb.Append("

");

 

        tmp = sb.ToString();

    }

 

    private string V( int v ) {

        return string.Format("{0:X}" , v).PadLeft(2 , '0');

    }

 

 

等我一步一步解开他的混淆后,发现:它只是一个笑话!

 

另外说明一下:

在PHP 里没有直接使用 createimagefromgif 是因为:

imagecolorat returns the color index (position in the palette) for
palette based image or the color value for true color images.

imagecreatefromjpeg creates true color images, always.
imagecreatefromgif creates always palette based images and
imagecreatefrompng creates either palette or true color images as PNG
supports both image types.
<br/>

http://bugs.php.net/bug.php?id=40801



陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具