라이브러리

[PHP] Imagick::annotateImage - 이미지에 텍스트 주석 달기




Imagick::annotateImage() 함수

Imagick::annotateImage() 함수는 이미지를.annotateImage() 함수를 사용하여 텍스트를 추가할 수 있습니다. 이 함수는 이미지를 수정하지 않고 새로운 이미지를 반환합니다.

함수 시그니처

#hostingforum.kr
php

Imagick::annotateImage( $image, $x, $y, $font, $text )



- `$image` : 이미지를 나타내는 Imagick 객체입니다.
- `$x` : 텍스트의 x 좌표입니다.
- `$y` : 텍스트의 y 좌표입니다.
- `$font` : 사용할 폰트입니다.
- `$text` : 추가할 텍스트입니다.

예제

#hostingforum.kr
php

// 이미지 생성

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

$image->resizeImage(800, 600, Imagick::FILTER_LANCZOS, 1);



// 텍스트 추가

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!');

$image->annotateImage($image, 200, 200, 'arial.ttf', 'This is a test image.');



// 이미지 출력

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

echo $image;



이 예제에서는 이미지를 생성하고, 그 이미지를 800x600 크기로 리사이즈합니다. 그 후, `annotateImage()` 함수를 사용하여 텍스트를 추가합니다. 두 번째 텍스트는 첫 번째 텍스트보다 아래쪽에 추가됩니다.

폰트 설정

폰트를 설정하는 방법은 여러 가지가 있습니다. 예를 들어, 다음 코드는 Arial 폰트를 사용합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!');



폰트 파일은 현재 디렉토리에 있어야 합니다. 만약 폰트 파일이 다른 디렉토리에 있다면, 다음 코드를 사용하세요.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'path/to/arial.ttf', 'Hello, World!');



폰트 이름을 변경하고 싶다면, 다음 코드를 사용하세요.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('font' => 'arial.ttf', 'pointsize' => 24, 'fillcolor' => 'black'));



폰트 이름, 크기, 색상을 설정할 수 있습니다.

색상 설정

색상을 설정하는 방법은 여러 가지가 있습니다. 예를 들어, 다음 코드는 검은색으로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('fillcolor' => 'black'));



색상 이름을 사용할 수 있습니다. 예를 들어, 다음 코드는 빨간색으로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('fillcolor' => 'red'));



색상 코드를 사용할 수 있습니다. 예를 들어, 다음 코드는 #FF0000으로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('fillcolor' => '#FF0000'));



색상 코드를 사용할 때는 '#' 기호를 사용해야 합니다.

크기 설정

크기 설정하는 방법은 여러 가지가 있습니다. 예를 들어, 다음 코드는 24점으로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('pointsize' => 24));



크기 이름을 사용할 수 있습니다. 예를 들어, 다음 코드는 24pt로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('pointsize' => '24pt'));



크기 코드를 사용할 수 있습니다. 예를 들어, 다음 코드는 24px로 텍스트를 출력합니다.

#hostingforum.kr
php

$image->annotateImage($image, 100, 100, 'arial.ttf', 'Hello, World!', array('pointsize' => '24px'));



크기 코드를 사용할 때는 'px' 또는 'pt'를 사용해야 합니다.

이러한 예제를 통해 Imagick::annotateImage() 함수를 사용하여 이미지를 편집하고 텍스트를 추가하는 방법을 알 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 492 페이지

검색

게시물 검색