DrawSetFont not working, but still returning true

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
evank

DrawSetFont not working, but still returning true

Post by evank »

On Ubuntu Desktop 8.04, I'm trying to annotate an image and everything seems to work fine, except I cannot seem to set the font face. This happens across two different installs, one of which is using MagickWand and the other using Imagick. The code demonstrating this:

Code: Select all

<?php

// get current path
$path = dirname(__FILE__);

// die if font permissions are bad
if(!is_readable("{$path}/sample/FreeMono.ttf")) {
	die('Font is not readable!');
}

if(extension_loaded('imagick')) {
	$resource = new Imagick();
	$status = $resource->readImage("{$path}/sample/scale.gif");
	
	$draw = new ImagickDraw();
	
	$status = $draw->setFont("{$path}/sample/FreeMono.ttf");
	if($status !== TRUE) die('DrawSetFont failed!');
	
	$status = $draw->setFontSize(20.0);
	if($status !== TRUE) die('DrawSetFontSize failed!');
	
	$status = $resource->annotateImage($draw, 0, 50, 0, 'The quick fox jumps over the lazy dog.');
	
	header('Content-Type: image/gif');
	echo $resource;
	exit;
}

if(extension_loaded('magickwand')) {
	$resource = NewMagickWand();
	$status = MagickReadImage($resource, "{$path}/sample/scale.gif");
	
	$draw = NewDrawingWand();
	
	$status = DrawSetFont($draw, "{$path}/sample/FreeMono.ttf");
	if($status !== TRUE) die('DrawSetFont failed!');
	
	DrawSetFontSize($draw, 20.0);
	$status = MagickAnnotateImage($resource, $draw, 0, 50, 0, 'The quick fox jumps over the lazy dog.');
	
	header('Content-Type: image/gif');
	echo MagickEchoImageBlob($resource);
	exit;
}

die('No IM extension loaded');
Nothing fails, and I indeed get back an image annotated with text. The ttf file specified exists and is readable (chmodded to 777), and it works fine with GD. The font size is set correctly, and I can even use a PixelWand to set the text color, but no matter what ttf file I specify, it uses a default font face. And the DrawSetFont function returns a true value, as does Imagick's setFont method.

I had to compile ImageMagick from source, and had to disable OpenMP, could this have something to do with it? If not, what could be the problem?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: DrawSetFont not working, but still returning true

Post by magick »

Your script works properly for us. We're using ImageMagick 6.4.3-4. Also make sure your version of ImageMagick includes Freetype support. We get
  • identify -list configure
    ...
    DELEGATES autotrace bzlib fpx fontconfig freetype gs gvc jbig jpeg jp2 lcms lqr openexr png rsvg tiff x11 xml wmf zlib
    ...
Notice how Freetype is included as a supported delegate. It is needed to render fonts.
evank

Re: DrawSetFont not working, but still returning true

Post by evank »

aaack...that was it, I didn't have the freetype or fontconfig dev files available. I compiled and installed those, recompiled magick, and it works perfectly! thanks so much
onurkucukkece
Posts: 1
Joined: 2012-05-14T04:31:09-07:00
Authentication code: 13

Re: DrawSetFont not working, but still returning true

Post by onurkucukkece »

Hi

I'm having the same problem

I've installed freetype and fontconfig packages, reinstalled imagick but it still doesn't work.

I'm using ImageMagick 6.7.6-1 and Imagick 2.3.0

can it be because of Imagick version?
cccnikul
Posts: 2
Joined: 2012-07-13T00:50:13-07:00
Authentication code: 13

Re: DrawSetFont not working, but still returning true

Post by cccnikul »

Hello,

I have same issue of loading .ttf, .otf fonts in imagick. I have tried several ways but it loads default font only.
I have set font path like below,

$draw = new ImagickDraw();
$draw->setFont("/www/web/imagicksample/fonts/alittlepot.ttf");
and
$draw = new ImagickDraw();
$draw->setFont("/usr/share/fonts/alittlepot.ttf");

but it does not show any effect.

My imagemagick version is ImageMagick 6.3.7 and module version 2.3.0.
Also Freetype is installed in server though it shows under GD section under phpinfo.

Please guide me on this.

Thanks,
Nikul
Post Reply