This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-07-22 10:15:22

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Setting the font is killing me!

No exxageration, I'm using this php code to render text as an image for my online/offline API and I can't work out how to change the font?

Code:

<?PHP
//parser in spaces
$count = 1;
$string = $_GET['string'];
$parser = '';
while ($count < strlen($_GET['string'])){
    if(substr($string, $count, 1) == '_'){
        $parser = $parser . ' ';
    }
    else{
        $parser = $parser . (substr($string, $count, 1));
    }
    $count ++;
}
// Set font size
$font_size = 2;

// Create image width dependant on width of the string
$width  = imagefontwidth($font_size)*strlen($string);
// Set height to that of the font
$height = imagefontheight($font_size);
// Create the image pallette
$img = imagecreate($width,$height);
// Grey background
$bg    = imagecolorallocate($img, 222, 223, 223);
// Black font color
$color = imagecolorallocate($img, 0, 0, 0);
// Length of the string
$len = strlen($string);
// Y-coordinate of character, X changes, Y is static
$ypos = 0;
// Loop through the string
for($i=0;$i<$len;$i++){
    // Position of the character horizontally
    $xpos = $i * imagefontwidth($font_size);
    // Draw character
    imagechar($img, $font_size, $xpos, $ypos, $string, $color);
    // Remove character from string
    $string = substr($string, 1);   
   
}
// Return the image
header("Content-Type: image/gif");
imagegif($img);
// Remove image
imagedestroy($img);

?>

The Scratch font is generally agreed to be Trebuchet MS so it would be great to somehow get that font working on this... Any help would be appreciated as I don't know much about text rendering  smile

You can test it http://www.blocks.scratchr.org/API.php?action=text&amp;string=like_this

Code:

[img]http://www.blocks.scratchr.org/API.php?action=text&string=your_text[/img]

http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#2 2011-07-22 10:27:25

jslomba
Scratcher
Registered: 2009-09-25
Posts: 1000+

Re: Setting the font is killing me!

http://www.blocks.scratchr.org/API.php?action=text&amp;string=your_text


the the the the the

Offline

 

#3 2011-07-23 15:22:23

sparks
Community Moderator
Registered: 2008-11-05
Posts: 1000+

Re: Setting the font is killing me!

Anyone? There must be some phper who knows!


http://img541.imageshack.us/img541/7563/scratchbetabanner.png

Offline

 

#4 2011-07-23 20:41:47

rubiks_cube_guy238
Scratcher
Registered: 2009-07-02
Posts: 100+

Re: Setting the font is killing me!

I'm guessing this might be helpful? I don't know much about php  hmm


The glass is never half full nor half empty; it is twice as large as it needs to be.

Offline

 

#5 2011-07-23 21:47:07

Mcsugarface
Scratcher
Registered: 2009-11-16
Posts: 100+

Re: Setting the font is killing me!

Maybe the font needs to be installed on your computer?


Hi! I'm http://blocks.scratchr.org/API.php?user=USERNAMEHERE&amp;action=onlineStatus&amp;type=text!
http://internetometer.com/imagesmall/11070.png

Offline

 

Board footer