php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #21712 Using ImageCreateFromJPEG with ImageTTFText causes type to appear jagged
Submitted: 2003-01-17 08:47 UTC Modified: 2003-01-17 16:32 UTC
From: gkopp at ideastar dot com Assigned:
Status: Not a bug Package: GD related
PHP Version: 4.3.0 OS: RedHat 6.1
Private report: No CVE-ID: None
 [2003-01-17 08:47 UTC] gkopp at ideastar dot com
The following code creates a new JPEG image. It worked fine under PHP 4.2.3, but since the upgrade to PHP 4.3.0, the type now appears jagged and in some cases with smaller type, unreadable:

<?

Header("Content-type: image/jpeg");

$size = 36;
$x = 5;
$y = 50;

$imgname = "bluebox.jpg";
$im = ImageCreateFromJPEG ($imgname); /* Attempt to open */

$color  = ImageColorAllocate ($im, 255, 255, 255);

$font = "FRAMDCN.TTF";

ImageTTFText ($im, $size, 0, $x, $y, $color, $font, $label);

ImageJpeg($im,'',100);
ImageDestroy($im);

?>

ImageCreateFromPNG gives me the same results.

If replace the ImageCreateFromJPEG() with just an ImageCreate and give it a solid color, it looks fine. It seems to only be affected when I start the image with a template image.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-01-17 08:48 UTC] iliaa@php.net
Are you using bundled or non-bundled GD library? In case of the latter, what version of GD library are you using?
 [2003-01-17 09:18 UTC] gkopp at ideastar dot com
I assume the bundled library. Although the unbundled library did exist on this machine before I compiled the new PHP. And it was version 2.0.1.
 [2003-01-17 12:39 UTC] iliaa@php.net
Are the dimentions of the 'source' image greater, less then or equal to the size of the 'destination' image?
 [2003-01-17 12:59 UTC] gkopp at ideastar dot com
They are equal. Basically, this code takes a template image, and places some dynamic text on top of it. It's used to make custom header graphics for a site, without the need to create new images in Photoshop, etc.
 [2003-01-17 14:09 UTC] iliaa@php.net
I've tried to duplicate the problem you've described using PHP 4.3.0 using bundled GD and PHP 4.2.3 using standard GD. Both produce absolutely identical images with the TTF (arial) font that I've used.
What version of freetype library are you using and if possible can you put the 'good' & 'bad' image online for comparison reasons.
 [2003-01-17 14:33 UTC] gkopp at ideastar dot com
Not sure about which libttf version. I know I have freetype-2.0.9 installed on the machine with the link below. Not sure if that helps.

http://tpol.ideastar.com/test.php

The code that produces bad results:
<?php
$text = "Jagged Text";

Header("Content-type: image/png");

$source_file = "bluebox.jpg";
$target_id = ImageCreateFromJPEG ($source_file);

$fontsize = 36;
$xpos = 20;
$ypos = 40;

$font_color = ImageColorAllocate ($target_id, 255, 255, 255);
$font = "/usr/local/www/archer/FRAMDCN.TTF";

ImageTTFText ($target_id, $fontsize, 0, $xpos, $ypos, $font_color, $font, $text);

ImageJpeg($target_id); 
ImageDestroy($target_id);

?>

The code that produces good results (trial and error figured this one out):
<?
$text = "Clear Text";

header("Content-type: image/png");

$source_file = "bluebox.jpg";
$source_size = getimagesize($source_file);
$source_w = $source_size[0];
$source_h = $source_size[1];
$source_id = ImageCreateFromJPEG($source_file);

$target_id = ImageCreate ($source_w, $source_h);

ImageCopyResampled($target_id, $source_id, 0, 0, 0, 0, $source_w, $source_h, $source_w, $source_h);

$fontsize = 36;
$xpos = 20;
$ypos = 40;

$font_color = ImageColorAllocate ($target_id, 255, 255, 255);
$font = "/usr/local/www/archer/FRAMDCN.TTF";

ImageTTFText ($target_id, $fontsize, 0, $xpos, $ypos, $font_color, $font, $text); 

ImagePNG ($target_id); 
ImageDestroy ($target_id);

?>
 [2003-01-17 15:01 UTC] iliaa@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Using the latest snapshot with identical font, source image and test script I've created an image that is not jagged.
For reference I am including a URL to the image created using 4.3.1-dev + bundled GD library.
http://bb.prohost.org/img.jpg
 [2003-01-17 15:44 UTC] gkopp at ideastar dot com
It would appear that I might have been using the unbundled version of gd. I went back to my test machine and removed all references to gd in /usr/local and recomipiled. That seemed to do the trick. I did use the latest build as you suggested. I am going to go back and try recompiling my production machine using the same settings but using the release version of 4.3.0.

Thanks for your help.
 [2003-01-17 16:32 UTC] gkopp at ideastar dot com
I recompiled php 4.3.0 again. My mistake was in the configure script. I put --with-gd="/usr/local" rather than just --with-gd by itself. This time, it used the bundled version of gd and the type came out okay.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 01:01:30 2024 UTC