GD & & MySQL Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

GD & & MySQL Problem

Post by Dale »

Couldn't figure out which room this is more relevant in, so i placed it in here.

I 'used' to have an image produced using this code below, but my server changed to GD 2.x on there servers, and the code no longer works. Could you please help me figure out why please :)

Code: Select all

<?php
$conn = mysql_connect("localhost","***","***");
mysql_select_db("***",$conn);

$sql = "SELECT * FROM counter WHERE section = 'dframe'";
	$result = mysql_query($sql,$conn) or die(mysql_error());
	while ($r = mysql_fetch_array($result)) {
		$id = $r['id'];
		$counth = $r['counth'];
}

$sql = "UPDATE counter SET counth = counth + 1 WHERE section = 'dframe'";
$result = mysql_query($sql,$conn) or die(mysql_error());

header ("Content-type: image/png");
$im = imagecreate(35,13);

//Here are some common color codes in case you want to change the colors.
$black = imagecolorallocate ($im,0x00, 0x00, 0x00);
$white = imagecolorallocate ($im,0xFF, 0xFF, 0xFF);
$black3 = imagecolorallocate ($im,0x69, 0x69, 0x96);
$black4 = imagecolorallocate ($im,0x69, 0x69, 0x96);

imagefilledrectangle($im, 0, 0, 450, 23, $black);

$font = 'verdana.ttf';

imagettftext($im, 7, 0, 2, 10, $white, $font, $counth);

imagepng ($im);
imagedestroy ($im);
?>
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

Change

Code: Select all

$im = imagecreate(35,13);
to

Code: Select all

$im = imagecreate(35,13) or die ("cannont initialize GD image stream");
What error do you now get?
Paul
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

I still get:

Code: Select all

<br />
<b>Fatal error</b>:  Call to undefined function:  imagettftext() in <b>/home/dframe/public_html/count.php</b> on line <b>28</b><br />
(Those HTML things do actually show).
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

Sounds like they updated the GD library but didn;t recompile the apache php module. To make sure GD is running in apache correctly, create this php file

Code: Select all

<?php
var_dump(gd_info());
?>
and run it. You should get something like
array(11) { ["GD Version"]=> string(27) "bundled (2.0.28 compatible)" ["FreeType Support"]=> bool(true) ["FreeType Linkage"]=> string(13) "with freetype" ["T1Lib Support"]=> bool(true) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }
If you don't then they didn't install GD correctly, or didn't re-compile the apache module.
PT
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

I got:
array(10) { ["GD Version"]=> string(27) "bundled (2.0.28 compatible)" ["FreeType Support"]=> bool(false) ["T1Lib Support"]=> bool(false) ["GIF Read Support"]=> bool(true) ["GIF Create Support"]=> bool(true) ["JPG Support"]=> bool(true) ["PNG Support"]=> bool(true) ["WBMP Support"]=> bool(true) ["XBM Support"]=> bool(true) ["JIS-mapped Japanese Font Support"]=> bool(false) }
User avatar
pthomas
Forum Commoner
Posts: 68
Joined: Wed Jan 19, 2005 11:28 am
Location: Cincinnati, OH

Post by pthomas »

Ah, there it is:
["FreeType Support"]=> bool(false)
True Type support isn't compiled in.

Here's another article to back this up:
User postings, 4th from the bottom: http://us4.php.net/function.imagettftext
If you compiled PHP yourself but get an error:
Fatal error: Call to undefined function imagettftext().

You need to compile PHP with more options.

--with-gd
--enable-gd-native-ttf
--with-png
--with-zlib-dir=/usr/local/lib/zlib-1.2.1
--with-ttf
--with-jpeg-dir=/usr/local/lib/jpeg-6b/
--with-freetype-dir=/usr/local/lib/freetype-2.1.9/
--with-xpm-dir=/usr/X11R6/

The next set deal with setting up GD, and the appropriate options. Just enabling GD, ttf, png & jpeg is NOT enough. You also need Freetype and XPM.
Let me know if it helps,
Paul
Post Reply