Image text size

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
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Image text size

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post by user___ »

feyd | Please use

Code: Select all

,

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

,

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]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I may be missing it, but where is $font_size being set?
EDIT| me thinks $font_size should just be $font
Last edited by s.dot on Mon Aug 13, 2007 10:18 am, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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?
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post 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).
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
user___
Forum Contributor
Posts: 297
Joined: Tue Dec 05, 2006 3:05 pm

Reply

Post 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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

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