Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with changing font of image generated by php

    Hey! I'm new here but I seem to be having trouble changing the font by the image generated by this php script:

    Code:
    preg_match_all('/<dd><div><p>([^<]+)<\/p><p><a href="\/gwt\/[^"]+">([^<]+)<\/a><\/p>\\s*(.*?)\\s*<\/div><\/dd>/i',file_get_contents('http://www.google.com/gwt/n?u=http%3A%2F%2Fwww.gaiaonline.com%2Fprofiles%2F%3Fmode%3Dcomments%26u%3D433232&_gwt_noimg=1'),$regs,PREG_SET_ORDER);
    $im=imagecreatetruecolor(275,500);
    imagesavealpha($im,true);
    $transparent=imagecolorallocatealpha($im,0,0,0,127);
    imagefill($im,0,0,$transparent);
    $messagecolor=imagecolorallocate($im,0,0,0);
    $username=imagecolorallocate($im,0,0,0);
    $timestamp=imagecolorallocate($im,0,0,0);
    $linecolor=imagecolorallocate($im,0,0,0);
    $line=2;
    for($i=0;$i<count($regs);$i++)
    {
    if($line<500-imagefontheight(2)*2+5)
    {
    imagestring($im,2,2,$line,$regs[$i][2],$username);
    imagestring($im,2,275-2-strlen($regs[$i][1])*imagefontwidth(2),$line,$regs[$i][1],$timestamp);
    $line+=imagefontheight(2);
    imageline($im,2,$line+2,275-2,$line+2,$linecolor);
    $line+=4;
    if(preg_match('/<br[^>]*>/i',$regs[$i][3]))
    {
    $message=preg_split('/<br[^>]*>/i',$regs[$i][3]);
    }
    else
    {
    $message=array($regs[$i][3]);
    }
    for($j=0;$j<count($message);$j++)
    {
    $submessage=explode('LELINEBREAK',wordwrap(preg_replace('/icon_biggrin\\.gif|icon_smile\\.gif|icon_redface\\.gif|icon_crying\\.gif|icon_stare\\.gif|icon_scream\\.gif|icon_gonk\\.gif|icon_blaugh\\.gif|icon_3nodding\\.gif|icon_xd\\.gif|icon_stressed\\.gif|icon_sweatdrop\\.gif|icon_heart\\.gif|icon_domokun\\.gif|icon_xp\\.gif|icon_eek\\.gif|icon_surprised\\.gif|icon_sad\\.gif|icon_wink\\.gif|icon_whee\\.gif|icon_confused\\.gif|icon_cool\\.gif|icon_lol\\.gif|icon_mad\\.gif|icon_razz\\.gif|icon_exclaim\\.gif|icon_rolleyes\\.gif|icon_twisted\\.gif|icon_evil\\.gif|icon_cry\\.gif|icon_question\\.gif|icon_idea\\.gif|icon_arrow\\.gif|icon_neutral\\.gif|icon_mrgreen\\.gif|icon_talk2hand\\.gif|icon_pirate\\.gif|icon_rofl\\.gif|icon_4laugh\\.gif|icon_ninja\\.gif|burning_eyes\\.gif|cheese_whine\\.gif|dramallama\\.gif|wahmbulance\\.gif|emo\\.gif|/i','',html_entity_decode(strip_tags($message[$j]))),floor(275/imagefontwidth(2))-1,'LELINEBREAK',true));
    for($k=0;$k<count($submessage);$k++)
    {
    if($line<500-imagefontheight(2)+1)
    {
    imagestring($im,2,2,$line,$submessage[$k],$messagecolor);
    $line+=imagefontheight(2);
    }
    }
    }
    $line+=4;
    }
    }
    header('content-type:image/png');
    imagepng($im);
    Can someone give me a hand?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Can you be more specific as to what you are trying to do and what it is doing incorrectly? I'm not certain if you're looking at what it should generate from the given string or if you are referring to something like the font family. Can you expand a little please?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    New to the CF scene
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, basicly, this script generates this: Link

    As you can see, the font used in that generated image is the default. I'm trying to change the font using something like $font = imageloadfont("example.gdf");
    However, I'm not sure if that is the correct code or where to place it.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Ok I see it is the font set then you are working with.
    imageloadfont is the function you want to use, and the font in use needs to be in a location that the interpreter can access.
    Load it before you run an imagestring, and place it as the second parameter in the method:
    PHP Code:
    ...
    $font imageloadfont('example.gdf');
    ...
    $linecolor=imagecolorallocate($im,0,0,0);
    $line=2;
    for(
    $i=0;$i<count($regs);$i++)
    {
    if(
    $line<500-imagefontheight(2)*2+5)
    {
    imagestring($im,$font,2,$line,$regs[$i][2],$username);
    imagestring($im,$font,275-2-strlen($regs[$i][1])*imagefontwidth(2),$line,$regs[$i][1],$timestamp);
    ... 
    Try that out, and let us know if that helps!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    New to the CF scene
    Join Date
    May 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks! It worked, but only for the username.
    What if I wanted the message to change font?

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Everytime you run an imagestring call, all you need to do is pass the variable that has been assigned to the font load. In our case, it was $font.
    I'm winging it here (been awhile since I created images), but I'm pretty sure the parameter list is:
    imagestring($imageHandle, $font, $height, $width, $text, $fontColour);
    The height and width may be backwards, idk for certain.

    For your actual line of code, just do the exact change that you did with the first two parts:
    Code:
    imagestring($im, $font,2,$line,$submessage[$k],$messagecolor);
    // Change here     ^
    Hope that helps!
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •