Page 1 of 1

Fontstyle not working

Posted: 2008-10-21T02:20:20-07:00
by skyjan
base from the manual
ImagickDraw::setFontStyle — Sets the font style to use when annotating with text

however things not working

Code: Select all

<?php
/* Define width and height of the thumbnail */
$width = 100;
$height = 100;
/* Instanciate and read the image in */
$im = new Imagick( "walalang/Sunset.jpg" );
/* Fit the image into $width x $height box
 The third parameter fits the image into a "bounding box" */
$im->thumbnailImage( null, 75 );
/* Create a canvas with the desired color */
$canvas = new Imagick();
$canvas->newImage( $width, $height, new ImagickPixel('#CCCCCC'));
$canvas->setImageFormat('jpeg');
/* Get the image geometry */
$geometry = $im->getImageGeometry();
/* The overlay x and y coordinates */
$x = ( $width - $geometry['width'] ) / 2;
$y = ( $height - $geometry['height'] ) / 2;
/* Composite on the canvas  */
$draw = new ImagickDraw();
$draw->setFontStyle( Imagick:: STYLE_ITALIC );

 $draw->setFont( "Fonts/arial.ttf" );

 $draw->setFontSize( 12 );
 
$draw->setFillColor( new ImagickPixel("#000000") ); // FONT COLOR
 $draw->setGravity( Imagick:: GRAVITY_CENTER );

 $im->annotateImage( $draw, 0, 0, 0, "hello worlds" );
$canvas->compositeImage( $im, imagick::COMPOSITE_OVER, $x, $y );

$canvas->drawImage($draw);


/* Output the image*/
header( "Content-Type: image/jpeg" );
echo $canvas;
?>



when i remove the FONT (FONT/arial.ttf) the fontstyle is working

any ideas ?

thanks for any input

Re: Fontstyle not working

Posted: 2008-11-25T04:17:52-07:00
by gpalmer711
Make sure that the following line is using the correct capitalisation and that the font does exist in the folder

$draw->setFont( "Fonts/arial.ttf" )

Re: Fontstyle not working

Posted: 2009-06-23T18:02:04-07:00
by robcolburn
I doubt that you could do that. "Normal", "Bold", "Italic", and "Bold Italic" are stored as separate files.

Fonts/arial.ttf
Fonts/arialb.ttf
Fonts/ariali.ttf
Fonts/arialbi.ttf

I believe the FontStyle affects the built-in Font Constants. So, when you say setFont, you are over-writing the fontStyle.

Get it?