2011-09-19 7 views
0
내가 올바른 색상으로 작성과 데 문제가

:색상 진수

$bgColor = '9EA5FF'; 
imagefilledrectangle($im, 0, 0, 11, 214,'0x' . $bgColor); 

또는

$bgColor = '0x9EA5FF'; 
imagefilledrectangle($im, 0, 0, 11, 214,$bgColor); 

코드 (들) 위의 제곱에 기입하지 않는 것 같다 그것은 (그냥 검은 색)하지만이 코드 :

imagefilledrectangle($im, 0, 0, 11, 214,'0x9EA5FF'); 

않습니다.

내가 뭘 잘못하고 있니?

답변

1

imagecolorallocate() 함수로 $ bgColor 변수를 설정해보십시오. 원하는 색상의 RGB 삼중 항을 사용하십시오. imagecolorallocate()는 imagefilledrectangle()에 전달 될 색상 식별자를 반환하도록 설계되었습니다.

GD의 설명서에 따르면 "imagecolorallocate()를 호출하여 이미지가 나타내는 이미지에 사용될 각 색상을 만들어야합니다."

+0

어떻게해야할까요? – StealthRT

+0

$ bgColor = '9EA5FF'를 나타내는 줄을 바꿀 수 있습니다. 이걸로 $ bgColor = imagecolorallocate ($ im, 168, 155, 255); – Andrew

+0

나는 그것을 얻었다 :) 고마워! – StealthRT

0
function html2rgb($color) 
{ 
    if ($color[0] == '#') 
     $color = substr($color, 1); 

    if (strlen($color) == 6) 
     list($r, $g, $b) = array($color[0].$color[1], 
          $color[2].$color[3], 
          $color[4].$color[5]); 
    elseif (strlen($color) == 3) 
     list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]); 
    else 
     return false; 

    $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); 

    return array($r, $g, $b); 
} 


$theRGB = html2rgb($bgColor); 
$background = imagecolorallocate($im, $theRGB[0], $theRGB[1], $theRGB[2]); 
imagefilledrectangle($im, 0, 0, 11, 214,$background); 
관련 문제