Annotate vs label vs caption

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
hivens
Posts: 8
Joined: 2017-02-24T03:49:36-07:00
Authentication code: 1151

Annotate vs label vs caption

Post by hivens »

I'm a bit stuck with this particular project, and I've been trying to implement some advice I received on this forum earlier today without much luck. I have a script that works but I don't know why I would choose to use caption/label over annotate, and how I would implement that.

Code: Select all

<?php

$text = 'The quick brown fox jumps over the lazy dog';
$width = 1000;
$height = 1000;

$textBackground = new ImagickPixel('transparent');
$textColor = new ImagickPixel('#000');

$gradient = new Imagick();
$gradient->newPseudoImage($width, $height, 'gradient:blue-red');

$image = new Imagick();
$image->newImage($width, $height, $textBackground);

$gradient->setImageColorspace($image->getImageColorspace());

$draw = new ImagickDraw();
$draw->setFillColor($textColor);
$draw->setFontSize( 10 );

$image->annotateImage($draw, 10, 45, 0, $text);

$gradient->compositeImage($image, Imagick::COMPOSITE_MATHEMATICS, 0, 0);
$gradient->setImageFormat('png');

header('Content-type: image/png');
echo $gradient;
return;
?>
P.s I'm sorry for a second post, I mucked up posting my first one - perhaps I should I have just edited this on top instead.
P.p.s My version is Version: ImageMagick 6.7.2-7 2016-06-17 Q16
Last edited by hivens on 2017-02-24T15:52:14-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Composite Image for gradient and text

Post by fmw42 »

I think you want

Code: Select all

$gradient->compositeImage($image, Imagick::COMPOSITE_OVER, 0, 0);
but before that you need to set the gravity to center. see

http://us3.php.net/manual/en/imagick.setgravity.php
hivens
Posts: 8
Joined: 2017-02-24T03:49:36-07:00
Authentication code: 1151

Re: Annotate vs label vs caption

Post by hivens »

Ok I will try that, thank you.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Annotate vs label vs caption

Post by fmw42 »

After annotating, you probably want to trim the image to just fit the text before compositing over the background image, so that it centers properly.
Post Reply