Jump to content

Image Magick Text Gradient


Goose

Recommended Posts

I would like to dynamically generate text filled in with a gradient using some graphics library. Currently I've gotten Image Magick to do most of what I want (using non-standard fonts, centering, etc.) but I still haven't figured out the gradient part. Does anyone know how to make Image Magick fill the text with a gradient color or know of another library I can do this with?

 

Thanks!

 

<?php

$canvas = new Imagick();

$text = $_GET['text'];
if(empty($text)){
    $text = "Unknown";
}

// sanitize, remove non-words and non-spaces
$text = preg_replace("/[^\S ]/","", $text);

$draw = new ImagickDraw();

// set font
$draw->setFont("DejaVuSerif.ttf");
$draw->setFontSize(32);
$draw->setFillColor('#ffffff');

// center the $draw object
$draw->setGravity(Imagick::GRAVITY_CENTER);

$canvas->newImage(400,50, 'none');

// draw the text onto the canvas
$canvas->annotateImage($draw, 0, 0, 0, $text);

// png is 1337
$canvas->setImageFormat('png');

header("Content-Type: image/png");
echo $canvas;

?>

 

When I call this script passing in the phrase "this is a test", I get the following image:

 

sample.png

Link to comment
https://forums.phpfreaks.com/topic/200730-image-magick-text-gradient/
Share on other sites

Here are some examples:

 

-t "SOME GRADIENT TEXT" -s gradient -e normal -f Arial -p 48 -c skyblue-black -b white -o black -l 1 -u none -A 0

 

-t "SOME GRADIENT TEXT" -s gradient -e normal -f Arial -p 48 -c skyblue-black -b white -o black -l 1 -u none -A 180

 

-t "SOME GRADIENT TEXT" -s gradient -e normal -f Arial -p 48 -c skyblue-black -b white -o black -l 1 -u none -A 90

 

Source: http://www.fmwconcepts.com/imagemagick/texteffect/index.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.