text water mark php 에 넣을만한거 샘플 구해주실래요?

text water mark php 에 넣을만한거 샘플 구해주실래요?

QA

text water mark php 에 넣을만한거 샘플 구해주실래요?

답변 3

본문

그누보드 용이 있을까요?

 

인터넷에 있 샘플 해봤는데 작동 안함 ㅠ

이 질문에 댓글 쓰기 :

답변 3


<?php
/* Get image info */
$Image = @ImageCreateFromJPEG ("YourImage.jpg") ;
$sx = imagesx($Image) ;
$sy = imagesy($Image) ;
if ($WatermarkNeeded)
    {
    /* Set text info */
    $Text="Copyright Ben Clay" ;
    $Font="arial.ttf" ;
    $FontColor = ImageColorAllocate ($Image,255,255,255) ;
    $FontShadow = ImageColorAllocate ($Image,0,0,0) ;
    $Rotation = 30 ;
    /* Make a copy image */
    $OriginalImage = ImageCreateTrueColor($sx,$sy) ;
    ImageCopy ($OriginalImage,$Image,0,0,0,0,$sx,$sy) ;
    /* Iterate to get the size up */
    $FontSize=1 ;
    do
        {
        $FontSize *= 1.1 ;
        $Box = @ImageTTFBBox($FontSize,0,$Font,$Text);
        $TextWidth = abs($Box[4] - $Box[0]) ;
        $TextHeight = abs($Box[5] - $Box[1]) ;
        }
    while ($TextWidth < $sx*0.7) ;
    /*  Awkward maths to get the origin of the text in the right place */
    $x = $sx/2 - cos(deg2rad($Rotation))*$TextWidth/2 ;
    $y = $sy/2 + sin(deg2rad($Rotation))*$TextWidth/2 + cos(deg2rad($Rotation))*$TextHeight/2 ;
    /* Make shadow text first followed by solid text */
    ImageTTFText ($Image,$FontSize,$Rotation,$x+4,$y+4,$FontShadow,$Font,$Text);
    ImageTTFText ($Image,$FontSize,$Rotation,$x,$y,$FontColor,$Font,$Text);
    /* merge original image into version with text to show image through text */
    ImageCopyMerge ($Image,$OriginalImage,0,0,0,0,$sx,$sy,50) ;
    }
ImageJPEG ($Image) ;
?> 

[/code]

또는 워터마커용 이미지를 따로 준비해서 다음과 같이 작성할수 있습니다.


// 원본 이미지 로드
$originalImage = imagecreatefromjpeg('원본이미지.jpg');
// 워터마크 이미지 로드
$watermarkImage = imagecreatefrompng('워터마크이미지.png');
// 워터마크 이미지 크기 조정
$watermarkWidth = imagesx($watermarkImage);
$watermarkHeight = imagesy($watermarkImage);
$resizeRatio = 0.5; // 크기 비율 조정
$newWidth = $watermarkWidth * $resizeRatio;
$newHeight = $watermarkHeight * $resizeRatio;
$resizedWatermarkImage = imagescale($watermarkImage, $newWidth, $newHeight);
// 원본 이미지에 워터마크 적용
$positionX = 20; // 워터마크 x 좌표
$positionY = 20; // 워터마크 y 좌표
imagecopymerge($originalImage, $resizedWatermarkImage, $positionX, $positionY, 0, 0, $newWidth, $newHeight, 50); // 50은 투명도
// 새로운 이미지 저장
imagejpeg($originalImage, '워터마크적용된이미지.jpg');
// 메모리에서 이미지 제거
imagedestroy($originalImage);
imagedestroy($resizedWatermarkImage);
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 125,873
© SIRSOFT
현재 페이지 제일 처음으로