日期:2012-05-01  浏览次数:20392 次

PHP的
 
<style>
body{}
a{display: inline-block;width:1px;height:1px;}
</style>
<?php
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 = "<div>";
for($i = 0; $i < $h; $i++){
$str .= "<div>";
for($j = 0; $j <$w; $j++){
$rgb = str_pad(dechex(imagecolorat($im, $j, $i)), 6, "0", STR_PAD_LEFT);
$str .="<a style='background:#$rgb'></a>";