DJ Mike's Tutorials: PHP

Imagick Functions

^

ImagickDraw::setFont

Description:
bool ImagickDraw::setFont ( string $font_name )

Sets the fully-specified font to use when annotating with text.
Parameters:
font_name
A string representing a path to a font or the name of a built in font. To find out what fonts are built in to your server, use Imagick::queryFonts.
Return Values
Returns TRUE on success.

Example 1


<?
$text 
"DJ Mike";
$font "Bookman-DemiItalic";
$pointsize 100;
$depth 4;

# make a transparent pallete
$pallete = new Imagick;
$pallete->newimage(450,105"transparent");
# set pallet format to gif
$pallete->setimageformat("gif");

# make a draw object with settings
$draw = new imagickdraw();
$draw->setgravity(imagick::GRAVITY_CENTER);
$draw->setfont("$font");
$draw->setfontsize($pointsize);

# set font color white
$draw->setfillcolor("#ffffff");
# offset annotate
$pallete->annotateImage $draw,$depth ,-$depth-30$text );
$pallete->annotateImage $draw,-$depth ,-$depth-30$text );

# set font color black
$draw->setfillcolor("#000000");
# offset annotate
$pallete->annotateImage $draw,-$depth ,$depth-20$text );
$pallete->annotateImage $draw,$depth ,$depth-30$text );

# set font color blue
$draw->setfillcolor("#0000ff");
# center annotate on top of offset annotates
$pallete->annotateImage $draw,,00$text );

# blur
$pallete->gaussianBlurImage21.5 ); 

# output to browser
$pallete->setImageFormat("gif");
header"Content-Type: image/gif" );
echo 
$pallete;
?>

Example 2


<?
$text 
"DJ Mike";
$font "lokicola.ttf";
$fontsize 100;
$fontcolor "#aa0000";
$glow_radius 15;
# Three glow colors
$glow = array( "#ff0000""#ff8800""#ffff00" );

# moves text down
$offset 12;

# make a black pallete
$pallete = new Imagick;
$pallete->newimage(375,140"#000000");
# set pallet format to gif
$pallete->setimageformat("gif");

# make a draw object with settings
$draw = new imagickdraw();
$draw->setgravity(imagick::GRAVITY_CENTER);
$draw->setfont("$font");
$draw->setfontsize($fontsize);

# Loop through glow colors
foreach( $glow as $var)
{
 
$draw->setfillcolor("$var");
 
$pallete->annotateImage $draw,,$offset0$text );
 
$pallete->annotateImage $draw,,$offset0$text );
 
$pallete->BlurImage$glow_radius$glow_radius ); 
}

# top layer
$draw->setfillcolor("$fontcolor");
# center annotate on top of offset annotates
$pallete->annotateImage $draw,,$offset0$text );

# output to browser
$pallete->setImageFormat("gif");
header"Content-Type: image/gif" );
echo 
$pallete;
?>


^


Created by DJ Mike from Santa Barbara

DJ Mike


Dance Away Santa Barbara's Home Page
<a href="http://www.statcounter.com/" target="_blank"> <img src="http://c5.statcounter.com/counter.php?sc_project=1321035&java=0&security=da2193dc" alt="counter free hit invisible" border="0" /></a>