R

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

· 2009-09-15 (화) 21:18:12 · 3533 · 3

저녁에 문득 생각나서 ..ㅋㅋ
이미지의 좌표별 색상값을 뽑아 내어 테이블로 똑같은 이미지를 만들수 있지 않을까하는 생각에  시도해보았습니다.
아래 이미지는 결과물입니다.
익스에서는 제대로 된값이 나오질 않더군요..^^
조그만 이미지 도 제대로 값을 출력해내지 못하고 있네요.
아래 이미지는 파폭에서 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개

2009-09-15 (화) 23:04:45
성능 테스트 용으로 좋겠습니다. ^^
2009-09-21 (월) 10:35:51
..
멋지네요.. ^^

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

프로그램

8,188건
+
제목 글쓴이 날짜 조회
12-08-29 조회 4,066
12-08-07 조회 3,749
12-08-03 조회 3,557
12-07-31 조회 3,665
12-07-30 조회 3,614
12-07-16 조회 3,839
12-07-15 조회 3,623
12-07-07 조회 3,522
12-07-06 조회 3,715
12-07-03 조회 3,686
12-06-29 조회 3,272
12-06-22 조회 3,647
12-06-17 조회 3,890
12-05-21 조회 3,823
12-05-02 조회 3,392
12-05-02 조회 4,186
12-05-02 조회 3,301
12-04-30 조회 3,482
12-04-30 조회 3,177
12-03-17 조회 4,023
12-03-10 조회 3,371
12-03-08 조회 3,901
12-03-03 조회 3,582
12-02-27 조회 4,999
12-02-17 조회 4,324
12-02-16 조회 4,574
12-02-03 조회 3,289
12-01-31 조회 3,183
12-01-24 조회 3,150
12-01-17 조회 3,874
12-01-05 조회 3,430
11-12-30 조회 3,154
11-12-23 조회 4,710
11-12-08 조회 3,437
11-12-07 조회 4,420
11-11-27 조회 3,821
11-11-25 조회 4,174
11-11-23 조회 3,637
11-11-22 조회 3,486
11-11-09 조회 3,207
11-10-23 조회 3,118
11-10-19 조회 3,091
11-10-08 조회 2,787
11-10-04 조회 2,793
11-10-04 조회 5,241
11-09-01 조회 4,318
11-08-13 조회 2,483
11-08-06 조회 3,167
11-07-11 조회 3,570
11-06-27 조회 2,942
11-06-21 조회 2,620
11-06-13 조회 2,403
11-06-07 조회 2,406
11-05-26 조회 2,400
11-04-20 조회 2,709
11-03-21 조회 2,804
11-03-18 조회 2,501
11-03-11 조회 2,530
11-02-07 조회 2,347
11-01-18 조회 2,671
11-01-12 조회 2,400
11-01-06 조회 2,495
10-12-10 조회 2,760
10-12-09 조회 2,590
10-12-08 조회 5,023
10-11-29 조회 2,675
10-11-28 조회 2,782
10-11-28 조회 2,620
10-11-19 조회 2,804
10-11-04 조회 2,692
10-10-21 조회 2,408
10-10-19 조회 3,354
10-10-12 조회 2,679
10-10-07 조회 2,512
10-09-30 조회 3,473
10-09-17 조회 3,869
10-09-17 조회 3,834
10-05-31 조회 3,513
09-12-31 조회 3,651
09-07-23 조회 4,975
08-09-16 조회 3,198
08-09-06 조회 2,933
08-09-04 조회 3,354
08-08-16 조회 4,404
08-08-15 조회 3,271
08-08-14 조회 4,481
08-08-12 조회 3,956
08-07-23 조회 2,780
08-07-10 조회 3,720
08-07-04 조회 2,944
08-06-27 조회 7,593
08-06-19 조회 4,880
08-05-27 조회 5,497
08-05-25 조회 5,325
08-05-23 조회 3,396
08-05-23 조회 4,540
08-05-21 조회 4,915
08-05-20 조회 4,038
08-05-20 조회 3,275
08-04-18 조회 4,319