질문과 답변 (구)

최근본상품
TOP
DOWN

질문과 답변 (구)

php 코드를 이윰코드로 변환하려면 어떻게 하나요??

2017.08.19 12:52 175 8

본문

<? foreach ( $pc->palette as $key => $value ) { ?><a href="board.php?bo_table=<?=$bo_table?>&sfl=wr_1&stx=<?=$value?>" class="pointColorBox" style="background-color:#<?=$value?>">&nbsp;</a>

0
로그인 후 평가 가능합니다.
- 지스타온 - 회원등급 : 지하계 / Level 4
포인트 1,143
경험치 1,537
[레벨 4] - 진행률 43%
- 가입일 : 2015-04-11 00:45:36
- 서명 : 미입력
- 자기소개 : 미입력

댓글목록 8

이윰IN님의 댓글

이윰IN 2017.08.19 13:16

다음과 같이 하시면 됩니다.


<!--{@ pc->palette }-->
<a href="board.php?bo_table={_bo_table}&sfl=wr_1&stx={.value_}" class="pointColorBox" style="background-color:#{.value_}">&nbsp;</a>
<!--{/}-->


한가지 체크하셔야 할 부분은요.
위 소스가 포함된 템플릿을 정의하고 출력하는 역할을 하는 php 파일에서는
$pc = new yourClassName;
$pc-> palette = array('','','');
$tpl->assign('pc',  $pc);

위와 같은 방식으로 처리 되어야 합니다.
감사합니다.

축하합니다. 첫댓글 포인트 33포인트를 획득하였습니다.

지스타온님의 댓글

너무 감사합니다^^ 문법마스터하기 간간히 하니 어렵네요 ㅠㅠ

지스타온님의 댓글

라이브 파일을 불러오고요

$pc = new pointColor();

클래스를 선언해주는데요 잘안되네요


라이브파일은요

<?
/**
 * @Author : Jongwan, Kim
 * @Email : master@webiz.kr
 * @Homepage : http://webiz.kr
 * @Update : 2010-08-15
 * @Version : 0.1
 */
class pointColor
{
var $palette = array("ff0000", "ff6c00", "ffc000", "56c40b", "1ba200", "00bdce", "0066ff", "8a00ff", "ff1ed3", "e9c2a9", "c68a12", "743515", "ffffff", "949494", "000000");
var $ptime = array("start" => 0, "end" => 0, "total" => 0);
var $debug = array();
var $filename = "";

/*
* dec -> hax
*/
function dec2hex($val)
{
$tmp = strtoUpper(DecHex($val&240));
$tmp = ( $tmp == "0" ) ? (STRING)"00" : $tmp;

if ( strlen($tmp) != 2 ) echo $val." ";

return $tmp;
}

/*
* hex -> dec
*/
function hex2dec($val)
{
$tmp = array(
"red" => hexdec(substr($val, 0, 2)),
"green" => hexdec(substr($val, 2, 2)),
"blue" => hexdec(substr($val, 4, 2))
);
return $tmp;
}

/*
* rgb -> hsv(hsb)
* http://www.php.net/manual/en/function.imagecolorsforindex.php
*/
function rgb2hsv($rgb)
{
$r = $rgb['red'];
$g = $rgb['green'];
$b = $rgb['blue'];

$minVal = min($r, $g, $b);
$maxVal = max($r, $g, $b);
$delta  = $maxVal - $minVal;

$v = $maxVal / 255;

if ($delta == 0) {
$h = 0;
$s = 0;
} else {
$s = $delta / $maxVal;
$del_R = ((($maxVal - $r) / 6) + ($delta / 2)) / $delta;
$del_G = ((($maxVal - $g) / 6) + ($delta / 2)) / $delta;
$del_B = ((($maxVal - $b) / 6) + ($delta / 2)) / $delta;

if ($r == $maxVal){
$h = $del_B - $del_G;
} else if ($g == $maxVal) {
$h = (1 / 3) + $del_R - $del_B;
} else if ($b == $maxVal) {
$h = (2 / 3) + $del_G - $del_R;
}

if ($h < 0){
$h++;
}
if ($h > 1) {
$h--;
}
}
$h = round($h * 360);
$s = round($s * 100);
$v = round($v * 100);

return array($h, $s, $v);
}

/*
HSB(HSV)

B < 15 : 검정
B >= 15
S < 20 : 무채색으로 간주
~ 33 : 검정
34 ~ 66 : 회색
67 ~ : 흰색
S >= 20 : 유채색
시작 < h < 끝 : 색상별
*/
function select($val)
{
// B check (밝기)
if ( $val[2] < 20 )
{
return $this->palette[14]; // 검정
}

// S check (채도)
if ( $val[1] < 20 )
{
if ( $val[2] < 50 )
return $this->palette[13]; // 회색
else
return $this->palette[12]; // 흰색
}
else
{
if ( $val[0] > 10 && $val[0] < 55 && $val[1] < 40 && $val[2] > 80 )
{
return $this->palette[9]; // 살색
}
else if ( $val[0] > 40 && $val[0] < 55 && $val[1] > 80 && $val[2] < 90 && $val[2] > 65 )
{
return $this->palette[10]; // 갈색
}
else if ( $val[0] > 330 && $val[0] < 25 && $val[1] > 80 && $val[2] < 50 )
{
return $this->palette[11]; // 진한갈색
}
else if ( $val[0] < 15 )
{
return $this->palette[0]; // 빨강
}
else if ( $val[0] < 40 )
{
return $this->palette[1]; // 주황
}
else if ( $val[0] < 60 )
{
return $this->palette[2]; // 노랑
}
else if ( $val[0] < 88 )
{
return $this->palette[3]; // 연두
}
else if ( $val[0] < 164 )
{
return $this->palette[4]; // 녹색
}
else if ( $val[0] < 193 )
{
return $this->palette[5]; // 하늘
}
else if ( $val[0] < 260 )
{
return $this->palette[6]; // 파랑
}
else if ( $val[0] < 287 )
{
return $this->palette[7]; // 보라
}
else if ( $val[0] < 320 )
{
return $this->palette[8]; // 핑크
}
else if ( $val[0] < 360 )
{
return $this->palette[0]; // 빨강
}
}
}

/*
* 실행
*/
function execute($filename)
{
if ( !$filename ) return false;

// 시작시간
$this->ptime['start'] = microtime();

// 파일 지정
$this->filename = $filename;

$size = getimagesize($this->filename);
switch ( $size['mime'] )
{
case "image/gif":
$im = imagecreatefromgif($this->filename);
break;
case "image/jpeg":
$im = imagecreatefromjpeg($this->filename);
break;
}

// 입력한 이미지정보 출력
//$this->printImageInfo();

// 실행된 시간 구하기
$this->getProcessTime("외부이미지 가져오기");

$result = array();
for ( $y = 0 ; $y < $size[1] ; $y++ )
{
for ( $x = 0 ; $x < $size[0] ; $x++ )
{
$pxlColor = ImageColorAt($im,$x,$y);
$pxlColorArr = ImageColorsForIndex($im, $pxlColor);
$result[$this->dec2hex($pxlColorArr["red"]) . $this->dec2hex($pxlColorArr["green"]) . $this->dec2hex($pxlColorArr["blue"])]++;
}
}
imagedestroy($im);

// 실행된 시간 구하기
$this->getProcessTime("이미지 분석");

// 검출된 색상 출력
//$this->printColorList($result);

$pointColor = array();
foreach ( $result as $color => $count )
{
$pointColor[$this->select($this->rgb2hsv($this->hex2dec($color)))]++;
}

// 실행된 시간 구하기
$this->getProcessTime("포인트 색상 검색");

// 많이 사용된 색상순으로 정렬
arsort($pointColor);

// 색상 출력
//$this->printColorList($pointColor, 10);

// 디버그 정보출력
$this->debug[] = array("title" => "전체시간", "value" => $this->ptime['total'] . " sec");
//$this->printDebug();

// 리턴
return $pointColor;
}

/*
* 이미지 정보
*/
function printImageInfo()
{
echo "<img src='".$this->filename."'><hr style='clear: both;' />";
}

/*
* 색상출력
*/
function printColorList($data, $limit = 0)
{
$i = 0;
foreach ( $data as $color => $count )
{
echo "<span title='".$count."' style=\"width: 20px; height: 20px; border: 1px solid #000; background-color:#".$color."; font-size: 0; margin: 2px; padding: 0; display: block; float: left;\">&nbsp;</span>";

$i++;
if ( $i >= $limit && $limit ) return false;
}

echo "<hr style='clear: both;' />";
}

/*
* 실행시간
*/
function getProcessTime($title)
{
$this->ptime['end'] = microtime();

$tmp = round((FLOAT)array_sum(explode(" ", $this->ptime['end']))-(FLOAT)array_sum(explode(" ",$this->ptime['start'])), 4);
$this->debug[] = array("title" => $title, "value" => $tmp . " sec");

$this->ptime['start'] = $this->ptime['end'];
$this->ptime['total'] += $tmp; // 전체시간
}

/*
* 키값만 배열로 변경
*/
function getKeysToArray($data)
{
$return = array();

if ( is_array($data) )
{
foreach ( $data as $key => $value )
{
$return[] = $key;
}
}

return $return;
}

/*
* RGB값으로 색상박스 출력
*/
function printColorBox($data, $box_width = 15, $box_height = 15)
{
if ( $data ) {
$tmp = explode(",", $data);
foreach ( $tmp as $key => $value ) {
$box .= "<span style='width: {$box_width}px; height: {$box_height}px; margin: 1px; border: 1px solid #aaa; display: inline; font-size: 0; background-color:#".$value."; float: left;'>&nbsp;</span>";
}
}

return $box;
}

/*
* 디버그 출력
*/
function printDebug()
{
echo "<hr style='clear: both;' />";
$this->printToTable($this->debug);
}

/*
* 배열을 테이블로 출력
*/
function printToTable($data)
{
if ( !is_array($data) ) return false;

echo "<table border=1 cellpadding=5 cellspacing=0 style='border: 1px solid #aaa; border-collapse:collapse; font: 12px gulim'>";
foreach ( $data as $key => $v )
{
echo "<tr><td style='background-color: #f5f5f5; border: 1px solid #ccc;'>".$v['title']."</td><td style='border: 1px solid #ccc;'>".$v['value']."</td><tr>";
}
echo "</table>";
}
} // end of 'class'
?>

이윰IN님의 댓글

이윰IN 2017.08.19 13:42

정확히 무엇을 하려 하시는지 모르겠지만 대략

$pc = new pointColor();
$palette = $pc->palette;
$tpl->assign('palette', $palette);
으로 처리하시고 ..

<!--{@palette }-->
<a href="board.php?bo_table={_bo_table}&sfl=wr_1&stx={.value_}" class="pointColorBox" style="background-color:#{.value_}">&nbsp;</a>
<!--{/}-->

이렇게 해보세요.

지스타온님의 댓글

$pc = new pointColor();
$palette = $pc->palette;
$tpl->assign('palette', $palette);

이걸 어디에 넣어야할까요 ??head 넣어도 안나와서요..

http://xgb.vhost.kr/bbs/board.php?bo_table=03_1&sfl=wr_1&stx=ff6c00

리스트에서요 색깔별로 포트폴리오 조회되게 하려구요 프로그램 이전하는데 어렵네요 흑흑

이윰IN님의 댓글

이윰IN 2017.08.19 14:18

/eyoom/core/board/view.skin.php 파일  중간 적당한 위치에 넣어 주시면 될 것 같습니다.
감사합니다.

축하합니다. 행운의 포인트 58포인트를 획득하였습니다.

지스타온님의 댓글

<!--{@ pc->palette }-->test
<a href="board.php?bo_table={_bo_table}&sfl=wr_1&stx={.value_}" class="pointColorBox" style="background-color:#{.value_}">&nbsp;</a>
<!--{/}-->test2

pc 값이 없는지 출력이 안됩니다.


리스트라서요

// pointColor
include_once(G5_LIB_PATH.'/pointColor.class.php');

$pc = new pointColor();
$palette = $pc->palette;
$tpl->assign('palette', $palette);

이렇게 넣어거든요

이윰IN님의 댓글

이윰IN 2017.08.19 19:04

위에 댓글에 소스가 바뀌었어요.

$pc = new pointColor();
$palette = $pc->palette;
$tpl->assign('palette', $palette);
으로 처리하시고 ..

<!--{@palette }-->
<a href="board.php?bo_table={_bo_table}&sfl=wr_1&stx={.value_}" class="pointColorBox" style="background-color:#{.value_}">&nbsp;</a>
<!--{/}-->

질문과 답변 (채택기능) 게시판이 신설되었습니다.
질문과 답변 (구) 게시판은 글쓰기가 제한되오니 착오 없으시길 바랍니다. (댓글 및 조회는 여전히 가능합니다.)

전체 2,800 건 - 1 페이지
제목
이윰넷 2017.10.24 468 0
도깨비뿅망치 2017.10.24 611 0
홍인 2017.10.24 466 0
tenuunsalhi 2017.10.23 489 0
jumphu 2017.10.23 476 0
jumphu 2017.10.23 455 0
GNDOON 2017.10.23 467 0
jumphu 2017.10.23 442 0
gang 2017.10.23 399 0
백철하 2017.10.22 458 0
클라네스 2017.10.22 420 0
gang 2017.10.21 456 0
최태풍 2017.10.21 461 0
꿈꾸는개발자 2017.10.20 431 0
부끄럼소년 2017.10.20 497 0