라이브러리

[PHP] GmagickDraw::annotate - 이미지에 텍스트를 그립니다.




GmagickDraw::annotate


GmagickDraw::annotate은 GmagickDraw 객체의 메소드로, 이미지에 텍스트를 추가하는 데 사용됩니다. 이 메소드는 텍스트를 이미지에 그려주고, 그려진 텍스트의 위치, 크기, 색상, 폰트 등 다양한 옵션을 설정할 수 있습니다.

사용법


GmagickDraw::annotate을 사용하려면, 먼저 GmagickDraw 객체를 생성하고, 그 객체에 이미지 데이터를 로드해야 합니다. 그 다음, annotate 메소드를 사용하여 텍스트를 이미지에 추가합니다.

예제


# 예제 1: 기본 텍스트 추가


#hostingforum.kr
php

<?php



// GmagickDraw 객체 생성

$draw = new GmagickDraw();



// 이미지 로드

$image = new Gmagick('example.jpg');



// 이미지 크기 얻기

$width = $image->getImageWidth();

$height = $image->getImageHeight();



// 텍스트 추가

$draw->annotateImage($image, 10, 10, 20, 'Hello, World!');



// 이미지 출력

$image->setImageFormat('jpg');

header('Content-Type: image/jpeg');

echo $image;



?>



# 예제 2: 텍스트 색상, 크기, 폰트 설정


#hostingforum.kr
php

<?php



// GmagickDraw 객체 생성

$draw = new GmagickDraw();



// 이미지 로드

$image = new Gmagick('example.jpg');



// 이미지 크기 얻기

$width = $image->getImageWidth();

$height = $image->getImageHeight();



// 텍스트 추가

$draw->setFillColor('red'); // 텍스트 색상 설정

$draw->setFont('arial.ttf'); // 폰트 설정

$draw->setFontSize(24); // 텍스트 크기 설정

$draw->annotateImage($image, 10, 10, 20, 'Hello, World!');



// 이미지 출력

$image->setImageFormat('jpg');

header('Content-Type: image/jpeg');

echo $image;



?>



# 예제 3: 텍스트 위치 설정


#hostingforum.kr
php

<?php



// GmagickDraw 객체 생성

$draw = new GmagickDraw();



// 이미지 로드

$image = new Gmagick('example.jpg');



// 이미지 크기 얻기

$width = $image->getImageWidth();

$height = $image->getImageHeight();



// 텍스트 추가

$draw->annotateImage($image, 100, 100, 20, 'Hello, World!'); // 텍스트 위치 설정



// 이미지 출력

$image->setImageFormat('jpg');

header('Content-Type: image/jpeg');

echo $image;



?>



참고


* GmagickDraw::annotate 메소드는 텍스트를 이미지에 추가할 때 사용됩니다.
* 텍스트 색상, 크기, 폰트, 위치 등을 설정할 수 있습니다.
* GmagickDraw 객체를 생성하고 이미지 데이터를 로드해야 합니다.
* annotate 메소드를 사용하여 텍스트를 이미지에 추가합니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 450 페이지

검색

게시물 검색