Goose Posted May 4, 2010 Share Posted May 4, 2010 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: Link to comment https://forums.phpfreaks.com/topic/200730-image-magick-text-gradient/ Share on other sites More sharing options...
The Little Guy Posted May 5, 2010 Share Posted May 5, 2010 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 Link to comment https://forums.phpfreaks.com/topic/200730-image-magick-text-gradient/#findComment-1053409 Share on other sites More sharing options...
Goose Posted May 6, 2010 Author Share Posted May 6, 2010 I was hoping that there would be a way to do it in PHP, as I don't want to enable the shell() command on my server, but if no one can think of a way, I may have to do that. Link to comment https://forums.phpfreaks.com/topic/200730-image-magick-text-gradient/#findComment-1053949 Share on other sites More sharing options...
Goose Posted May 8, 2010 Author Share Posted May 8, 2010 Well, after doing some more research I found this awesome JavaScript library that does exactly this: http://cufon.shoqolate.com/generate/ Link to comment https://forums.phpfreaks.com/topic/200730-image-magick-text-gradient/#findComment-1055047 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.