R

GD 를 이용한 테이블 포토 (imagecolorat)

저녁에 문득 생각나서 ..ㅋㅋ
이미지의 좌표별 색상값을 뽑아 내어 테이블로 똑같은 이미지를 만들수 있지 않을까하는 생각에  시도해보았습니다.
아래 이미지는 결과물입니다.
익스에서는 제대로 된값이 나오질 않더군요..^^
조그만 이미지 도 제대로 값을 출력해내지 못하고 있네요.
아래 이미지는 파폭에서 600 400 픽셀 이미지로 테스트 한 결과 입니다.
파폭도 완벽하게 출력해내지는 못합니다.
위쪽 파란색 테두리의 이미지가 원본이며 아래 이미지는 테이블로 만들어진 이미지 입니다.



아하 php 쏘스 입니다.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<?
 
$imgdir = "p.jpg"; // 이미지 경로를 적어주시면됩니다.

list($width, $height, $type, $attr) = getimagesize($imgdir); // 이미지 사이즈 및 타입을 구함.
$im = imagecreatefromjpeg($imgdir); 
 
function getimgcolorat($x, $y){
 global $type, $im;
 
 $rgb = imagecolorat($im, $x, $y); // 이미지에서 좌표값의 색상을 뽑아온다.
 //unset($im);
 return dechex($rgb);
 unset($rgb);
}
 
 $color = array();
 $c = 0;
 for($y=0; $y<$height; $y++){
  for($x=0; $x<$width; $x++){ 
   $imgcolor = getimgcolorat($x, $y);
   
   $key = $x.$y;
   if($data[$imgcolor]){
    $sellcolor[$key] = $data[$imgcolor];
   }else{
    $color[$c] = $imgcolor;
    $data[$imgcolor] = $c;
    $sellcolor[$key] = $c;
    $c++;
   }
   unset($imgcolor);
  }
 }
 unset($data);
 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>Untitled Document</title>
<style type="text/css">
<!--
.ts {
 width: 1px;
 height: 1px;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="10" cellpadding="10">
  <tr>
    <td bgcolor="#0099FF"><img src="<?=$imgdir?>" width="<?=$width?>" height="<?=$height?>"></td>
  </tr>
  <tr>
    <td>

   
    <table width="<?=$width?>" border="0" cellspacing="0" cellpadding="0">
    <?
 for($y=0; $y<$height; $y++){
  echo "<tr>";
  for($x=0; $x<$width; $x++){ 
   $key = $x.$y;
   $bgcolor = $color[$sellcolor[$key]];
   echo "<td bgcolor=\"#{$bgcolor}\" class=\"ts\"></td>";
  }
  echo "</tr>";
 }
 
 ?>
    </table>
   
    </td>
  </tr>
</table>
</body>
</html>

[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|

댓글 3개

성능 테스트 용으로 좋겠습니다. ^^
멋지네요.. ^^

이미지 복제 시간은 많이 안 걸리나요?
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
11-08-16 조회 2,446
11-08-16 조회 2,422
11-08-12 조회 2,267
11-08-02 조회 2,838
11-07-27 조회 2,224
11-07-25 조회 2,343
11-06-28 조회 2,530
11-06-06 조회 4,045
11-06-04 조회 2,627
11-04-25 조회 6,210
11-04-22 조회 2,707
11-04-21 조회 2,940
11-04-08 조회 3,351
11-03-31 조회 2,859
11-03-20 조회 3,288
11-03-10 조회 2,893
11-03-04 조회 3,208
11-03-03 조회 2,946
11-02-26 조회 4,374
11-02-14 조회 5,723
11-02-08 조회 3,329
11-01-30 조회 5,419
11-01-14 조회 5,219
11-01-14 조회 3,770
11-01-14 조회 2,917
11-01-14 조회 2,955
11-01-14 조회 3,103
11-01-12 조회 2,878
11-01-07 조회 4,528
10-12-29 조회 2,539
10-12-22 조회 2,492
10-12-05 조회 5,902
10-11-22 조회 5,263
10-11-13 조회 3,636
10-10-27 조회 3,243
10-10-21 조회 2,941
10-09-21 조회 2,944
10-09-17 조회 3,000
10-09-15 조회 3,445
10-09-14 조회 4,051
10-05-18 조회 2,934
10-02-17 조회 4,382
10-02-12 조회 3,135
09-12-14 조회 5,199
09-12-14 조회 6,066
09-09-19 조회 4,423
09-08-16 조회 6,274
09-07-22 조회 5,680
09-04-13 조회 3,082
09-03-15 조회 5,092
09-03-05 조회 3,922
09-02-09 조회 2,873
08-12-30 조회 3,057
08-12-06 조회 3,255
08-11-30 조회 3,601
08-10-18 조회 4,437
08-10-08 조회 3,827
08-09-19 조회 4,398
08-09-05 조회 3,030
08-09-05 조회 5,129
08-09-05 조회 3,006
08-09-05 조회 3,616
08-09-05 조회 3,516
08-09-01 조회 4,538
08-08-07 조회 2,789
08-06-08 조회 3,255
08-06-02 조회 2,861
08-05-26 조회 5,279
08-05-09 조회 4,338
08-04-22 조회 3,946
08-04-17 조회 4,525
08-04-17 조회 5,596
08-04-17 조회 3,738
08-04-17 조회 8,720
08-04-17 조회 4,636
08-04-17 조회 4,548
08-04-09 조회 3,092
08-03-31 조회 3,578
08-03-26 조회 3,291
08-03-25 조회 3,578
08-03-25 조회 4,002
08-03-25 조회 4,031
08-03-25 조회 3,697
08-03-25 조회 3,587
08-03-25 조회 3,592
08-03-25 조회 5,283
08-02-03 조회 5,368
08-01-18 조회 6,662
08-01-17 조회 3,955
08-01-17 조회 3,772
08-01-12 조회 4,074
08-01-08 조회 3,387
07-12-28 조회 4,665
07-12-04 조회 3,547
07-11-30 조회 5,153
07-11-30 조회 5,753
07-11-02 조회 4,048
07-10-24 조회 4,030
07-10-24 조회 3,308
07-10-24 조회 3,419