Fontstyle not working

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
skyjan

Fontstyle not working

Post 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
gpalmer711

Re: Fontstyle not working

Post 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" )
robcolburn

Re: Fontstyle not working

Post 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?
Post Reply