썸네일시 바탕(배경)이미지 넣기 (water mark) > PHP

본문 바로가기
사이트 내 전체검색

PHP

썸네일시 바탕(배경)이미지 넣기 (water mark)

페이지 정보

profile_image
작성자 최고관리자
댓글 0건 조회 4,827회 작성일 21-02-09 11:50

본문

// 특정한 사이즈가 정해진 상태에서 여백에 흰색이미지 넣기 
 (썸네일 생성시 가로세로가 정해진 상태에서 세로 이미지나 썸네일보다 작은 이미지일 경우 바탕에 흰색 배경 합치기)

 $tmp_fileName = "{$tmp_file[0]}.pnm";    // 배경이미지 위에 들어갈 이미지
$thumfile = $photo_dir . "/" . $thumfileName;  // 최종 만들 이미지

$xsize = (int)(($Imgsize[0] * $세로사이즈 ) / $Imgsize[1]);
 exec( "pnmscale -xsize $xsize -ysize $세로사이즈 $tmp_fileName | cjpeg -progressive -optimize -smooth 20 -outfile $thumfile" );

 //-- 배경 이미지랑 합치기 start
 $photoBackImg = "photo_thumback.jpg";  // 배경이미지
$backImg = imagecreatefromjpeg($photoBackImg);

 if($ext == 'gif'){
    $thumImg = imagecreatefromgif($thumfile);
 } else {
    $thumImg = imagecreatefromjpeg($thumfile);
 }   


 //bool imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )

 $xposition = (int)(($가로사이즈 / 2) - ( $xsize / 2 ));
 @imageCopyMerge($backImg,$thumImg,$xposition,0,0,0,$xsize,$세로사이즈,100); //220
 @imagejpeg($backImg,$thumfile,75);
 @ImageDestroy($backImg);
 //-- 배경 이미지랑 합치기 end


 ==========================================================================================
        // water mark";
        $waterImg = "./img/mark_b2.gif"; 
        $tmpwaterImg = imagecreatefromgif($waterImg);

        //원본 이미지
      if($ext == 'gif'){
            $downImg = imagecreatefromgif($uploadfile);
        } else {
            $downImg = imagecreatefromjpeg($uploadfile);
        }

                // 우측하단에 삽일할경우
        $xposition = (int)($Imgsize[0] - $src_x);
        $yposition = (int)($Imgsize[1] - $src_y);

        @imageCopyMerge($downImg, $tmpwaterImg,$xposition,$yposition,0,0,$src_x,$src_y,100);
        @imagejpeg($downImg,$uploadfile,100);
        @ImageDestroy($downImg);


 ==    png file  ==========================================================================
원본파일 : $uploadfile
 water mark : $waterImg
 $Imgsize = GetImageSize($uploadfile);

                //----    water mark Start    ---- //
                $tmpwaterWidth = 210;
                $tmpwaterHeight = 62;
                $tmpwaterImg = imagecreatetruecolor($tmpwaterWidth, $tmpwaterHeight); 
                $black = imagecolorallocate($tmpwaterImg, 0, 0, 0); 
               
                imagecolortransparent($tmpwaterImg, $black); 
                $waterImg = "./img/mark_carnphoto1.png";
                $watersource = imagecreatefrompng($waterImg); 
               
                //bool imagecopyresampled ( $dst_image , $src_image , $dst_x , int $dst_y , int $src_x , int $src_y , int $dst_w , int $dst_h , int $src_w , int $src_h )
                //imagecopyresampled($tmpwaterImg, $watersource, 0, 0, 0, 0, $tmpwaterWidth, $tmpwaterHeight, imagesx($watersource), imagesy($watersource)); 
                imagecopyresampled($tmpwaterImg, $watersource, 0, 0, 0, 0, $tmpwaterWidth, $tmpwaterHeight, $tmpwaterWidth, $tmpwaterHeight); 
               
                if($ext == 'gif'){
                    $downImg = imagecreatefromgif($uploadfile);
                } else {
                    $downImg = imagecreatefromjpeg($uploadfile);
                }
               
                $xposition = (int)($원본가로사이즈 - $tmpwaterWidth);
                $yposition = (int)($Imgsize[1] - $tmpwaterHeight);
                @imageCopyMerge($downImg, $tmpwaterImg,$xposition,$yposition,0,0,$tmpwaterWidth,$tmpwaterHeight,100);
                @imagejpeg($downImg,$uploadfile,100);
                @ImageDestroy($downImg);
                @ImageDestroy($tmpwaterImg);
                //----    water mark End    ---- //

댓글목록

등록된 댓글이 없습니다.

회원로그인

회원가입

  • 게시물이 없습니다.

접속자집계

오늘
1,849
어제
4,039
최대
6,642
전체
830,364
contact : webmaster@beautipia.co.kr
Copyright © beautipia.co.kr. All rights reserved.