Page 1 of 1
Image text size
Posted: Mon Aug 13, 2007 9:44 am
by user___
Hi guys,
I have a class which generates secure images but I can not set the size of the text outputted on it. I post you only the function that sets the text but not the whole class due to its length.
Code: Select all
imagestring($image, $font, $left, $top, $rand, $textColor);
//$image is an image resource
//$font is a .gdf font file
//$left
//$top
//$rand is the text
//$textColor is the color of the text
I know that in that way the size of the text is the size of the font but I compiled my custom font which size is:
char height:93;
char width :73;
but I got the same results.
Do you know how to fix that?
Posted: Mon Aug 13, 2007 9:48 am
by onion2k
You seem to be missing the imageloadfont() function. It might be somewhere else in your function I suppose. If it's not then the solution is pretty obvious.
Reply
Posted: Mon Aug 13, 2007 10:06 am
by user___
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
No, I do not miss it. This is what I have.
Code: Select all
$image = imagecreate($width, $height);
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, rand(0, 33), rand(0, 33), rand(0, 33));
//Write the random number
$font = imageloadfont($this->site_font_path.$this->site_font_validation);
//Random position for the text
$top = 0;
$left = 0;
$top = rand(3, $height-33);
$left = rand(3, $width-93);
imagestring($image, $font_size, $left, $top, $rand, $textColor);
I have it so do you have any idea where does the problem may come from?
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Mon Aug 13, 2007 10:16 am
by s.dot
I may be missing it, but where is $font_size being set?
EDIT| me thinks $font_size should just be $font
Posted: Mon Aug 13, 2007 10:17 am
by onion2k
Code: Select all
$font = imageloadfont($this->site_font_path.$this->site_font_validation);
...
imagestring($image, $font_size, $left, $top, $rand, $textColor);
You've got $font holding the font, and $font_size in the imagestring call.
Reply
Posted: Tue Aug 14, 2007 3:09 am
by user___
Sorry, guys it is my mistake. Yes, you do not miss anything. I am the one who misses important things. On the place of $font_size I put $font but because I made some modifications yesterday I sent you a mistaken code. So this is what I have.
Code: Select all
$image = imagecreate($width, $height);
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, rand(0, 33), rand(0, 33), rand(0, 33));
//Write the random number
$font = imageloadfont($this->site_font_path.$this->site_font_validation);
//Random position for the text
$top = 0;
$left = 0;
$top = rand(3, $height-33);
$left = rand(3, $width-93);
imagestring($image, $font, $left, $top, $rand, $textColor);
Do you have any ideas?
Posted: Tue Aug 14, 2007 3:22 am
by onion2k
That code works fine for me.
Code: Select all
<?php
$rand = "hello";
$image = imagecreate(600, 300);
$bgColor = imagecolorallocate ($image, 255, 255, 255);
$textColor = imagecolorallocate ($image, rand(0, 33), rand(0, 33), rand(0, 33));
//Write the random number
$font = imageloadfont("04b.gdf");
//Random position for the text
$top = 0;
$left = 0;
$top = 50+rand(3, $height-33);
$left = 200+rand(3, $width-93);
imagestring($image, $font, $left, $top, $rand, $textColor);
header("Content-type: image/png");
imagepng($image);
I had to make a couple of minor modifications like the path to the font, setting the text, and moving the position to somewhere that actually displayed on the image, but the font size is fine. I tried it with a couple of different size fonts and they were both ok.
Is your font path setting definitely correct?
Reply
Posted: Tue Aug 14, 2007 5:10 am
by user___
Thank you onion2k but I still have my letters small. My fontseems to be fine(Arial in .gdf format). The problem is that I can not set the size of symbols displayed. For example if I want them huge(three symbols which takes up the whole screen).
Posted: Tue Aug 14, 2007 5:48 am
by onion2k
You do know that gdf fonts are fixed size, right? If you want bigger text you have to rebuild the gdf file with bigger letters.
Reply
Posted: Tue Aug 14, 2007 5:52 am
by user___
Yes, I do. I use that tool
http://www.wedwick.com/wftopf.exe to convert fonts. Is there any site where I can download fonts from?
Posted: Tue Aug 14, 2007 6:57 am
by onion2k
I've just tried that tool with a normal TTF font and it works no bother.
EDIT: Except the 72pt font I made ended up being a 620kb file. Yikes.