워터마크 때문에 질문 드립니다.

워터마크 때문에 질문 드립니다.

QA

워터마크 때문에 질문 드립니다.

본문

이미지 파일이 투명색일 경우 검게 나오는데 배경생을 흰색으로 나오게 할려면 어떻게 해야 할까요?

 


<?php
include_once("./_common.php");
/******************************************************************************
Program: watermark-text.php
Copyright (c) 2008 sonosini All rights reserved.
Do not remove this notice
- 사용법 -
<img src='maketext.php?photo=1.jpg'>
******************************************************************************/
   $font_File="./data/logo-w/" . $config['cf_watermark_font']; // 워터마크 폰트 주소 (*ttf 폰트 파일만 가능)
        
   $font_size_auto = true;                         //$font_size_auto = true; 일경우라도  $font_size='';가 공란일경우만 적용
   $font_size ='';                                 // $font_size = 10;과같이 숫자 있을경우에는 $font_size_auto = true; 는 무시됨
   $color = '#ffffff';                             //텍스트로고 색깔
   $drop_shadow = true;                            //텍스트로고에 그림자 효과  
   $shadow_color = '#606060';                      //$drop_shadow = true; 일경우만 적용
   $angle=0;                                       //양수증가는 위쪽 세로글씨,음수일경우 아래쪽 세로글씨
   $quality=1280;                                  //출력된 이미지의 해상도 낮을수록 선명치 못함
   $font = $font_File;                             //폰트 선택
   $transparency =30;                              //증가할수록 불투명해짐
   $logo_location = 'top_l';                       //top_l,top_r,center,bottom_l,bottom_r
   $offset_x=0;                                    //$logo_location기준으로 양수는 좌로 이동,음수는 우로 이동
   $offset_y=10;                                   //$logo_location기준으로 양수는 위로 이동,음수는 아래로 이동
   $SourceImage = $_GET['photo'];
   $WaterMarkText = "" . $g4['url'] . "/ - " . $config['cf_title'];
   //--------------------------------------------------------------------------------------
   $img_name=explode('/',$SourceImage);
   $img_name_right = sizeof($img_name) - 1;
   $img_name=explode('.',$img_name[$img_name_right]);
   //$WaterMarkedImage =$img_name[0].'_marked.'.$img_name[1];//$this_skin.'/watermark_temp/'.$img_name[0].'_marked.'.$img_name[1];

   list($width, $height) = getimagesize($SourceImage);
   $image_ct = imagecreatetruecolor($width, $height);
   if($img_name[1] == "gif")  $image = imagecreatefromgif($SourceImage); 
   if($img_name[1] == "jpg" or $img_name[1] == "jpeg") $image = imagecreatefromjpeg($SourceImage);  
   if($img_name[1] == "png")  $image = imagecreatefrompng($SourceImage);  
   if (!$image) die();
 
   imagecopyresampled($image_ct, $image, 0, 0, 0, 0, $width, $height, $width, $height); 
   
   $color = sscanf($color, '#%2x%2x%2x');
   $color_r = $color[0];
   $color_g = $color[1];
   $color_b = $color[2];
 
   if ($font_size_auto) {
        if ($font_size == ''){
          if ($width <= '150px') $font_size = 0;
          elseif ($width <= '250px') $font_size = $config[cf_watermark_font_width];
          elseif ($width <= '450px') $font_size = $config[cf_watermark_font_width]+1;
          elseif ($width <= '550px') $font_size = $config[cf_watermark_font_width]+2; 
          elseif ($width <= '650px') $font_size = $config[cf_watermark_font_width]+3;
          elseif ($width <= '750px') $font_size = $config[cf_watermark_font_width]+4;
          elseif ($width <= '850px') $font_size = $config[cf_watermark_font_width]+5; 
          elseif ($width <= '980px') $font_size = $config[cf_watermark_font_width]+6; 
          else $font_size = $config[cf_watermark_font_width]+7; 
         }
   }
   $WaterMarkText= iconv("EUC-KR","UTF-8" ,$WaterMarkText); 
   $ttfsize = imagettfbbox($font_size, $angle, $font, $WaterMarkText);
   $ttfx = $offset_x + max($ttfsize[0],$ttfsize[2],$ttfsize[4],$ttfsize[6]);
   $ttfy = $offset_y + max($ttfsize[1],$ttfsize[3],$ttfsize[5],$ttfsize[7]);
   if ($logo_location == 'top_l') {$x=4; $y=$ttfy + 11; $s_x=5; $s_y=$ttfy + 12;}
   if ($logo_location == 'top_r') {$x=$width - $ttfx - 4; $y=$ttfy + 11; $s_x=$width - $ttfx - 5; $s_y=$ttfy + 12;}
   if ($logo_location == 'center') {$x=($width - $ttfx - 2)/2; $y=($height - $ttfy - 2)/2; $s_x=($width - $ttfx - 3)/2; $s_y=($height - $ttfy - 3)/2;}
   if ($logo_location == 'bottom_l') {$x= 2; $y=$height - $ttfy - 2; $s_x= 3; $s_y=$height - $ttfy - 3;}
   if ($logo_location == 'bottom_r') {$x=$width - $ttfx - 2; $y=$height - $ttfy - 2; $s_x=$width - $ttfx -3; $s_y=$height - $ttfy - 3;}

   
   if ($drop_shadow) {
      $scolor = sscanf($shadow_color, '#%2x%2x%2x');
      $scolor_r = $scolor[0];
      $scolor_g = $scolor[1];
      $scolor_b = $scolor[2];
   
   $color = imagecolorallocatealpha($image_ct, $scolor_r, $scolor_g, $scolor_b, $transparency);
   imagettftext($image_ct, $font_size,$angle,$x,$y, $color, $font, $WaterMarkText);
   }
  
    
   $color = imagecolorallocatealpha($image_ct, $color_r, $color_g, $color_b, $transparency);
   imagettftext($image_ct, $font_size,$angle,$s_x,$s_y, $color, $font, $WaterMarkText);
   
   if($img_name[1] == "gif") header("Content-Type: image/gif");  
   if($img_name[1] == "jpg" or $img_name[1] == "jpeg") header("Content-Type: image/jpeg"); 
   if($img_name[1] == "png") header("Content-Type: image/png");
   imagejpeg ($image_ct, null, $quality); 
  
   imagedestroy($image); 
   imagedestroy($image_ct); 
?> 
 

이 질문에 댓글 쓰기 :

답변 1


$file = imagecreatetruecolor($width, $height);
$new = imagecreatefrompng($this->file_tempname);
for($i=0; $i<256; $i++) { imagecolorallocate($file, $i, $i, $i); }
imagecopyresampled($file, $new, 0, 0, 0, 0, $width, $height, $this->file_width, $this->file_height); 
imagejpeg($file, $photo_dest, 100);

 

http://stackoverflow.com/questions/5688954/how-to-replace-black-background-with-white-when-resizing-converting-png-images-w 

 

참고

답변을 작성하시기 전에 로그인 해주세요.
전체 33
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1402호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT