TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 04-24-2008, 08:49 PM   #1 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default Dynamicly place text on a background image

Hey guys!

Sort of an interesting topic-title, wouldn't you say? Well then, let me explain.

We've got a huge upcoming lanparty and I wanted to make a signature for the clan. That's all good an fun, until I hit this little snag.

The fact of the matter is, I wanted to insert something like this.

1. A GET variable, like ?text=Still_{days}_to_go
2. Converted and replaced to "Still 8 days to go".
3. Create background image from a remote location
4. Create the string
5. Merge the images and position it on the pixels using the GET variable again.

Well, I can't even get past the problem with making a sort of cool string on a transparent background. So, PNG. The background image is JPEG and I want a PNG string to be outputted onto that image.

This is what I had so far.

PHP Code:
    /* Define the source and get the file size (width+height) */
    
$imageSource 'http://markernst.com/ZeldaSig.jpg';
    
$imageSize getimagesize$imageSource );
    
$imageWidth $imageSize[0];
    
$imageHeight $imageSize[1];
    
    
/* Make an image */
    
$imageCreate imagecreatefromjpeg$imageSource );
    
    
$textString stripslasheshtmlentities$_GET['text'] ) );
/*    $textSize = getimagesize( $textString );
    $textWidth = $textSize[0];
    $textHeight = $textSize[1];    */
    
$textLength strlen($textString)*7+9;
    
$textImage imagecreate $textLength24 );
        
$colorOne imagecolorallocate$textImage000);
        
$colorTwo imagecolorallocate$textImage255255255);
        
    
/* Set the Output, no echo's above! */
    
header("Content-type: image/jpeg"); 
    
    
/* Echo out the file */
    //imagestring($textImage, 3, 5, 5, $textString, $colorTwo);
    //imagepng($textImage);
    
imagejpeg($imageCreate''100);
    
imagedestroy($imageCreate); 
Help? (oh yeah, first off is creating the image, haven't made the bbcode/get str_replace function yet.)

/edit
The working project.
http://www.markernst.eu/countdown.php
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 04-26-2008, 09:04 PM   #2 (permalink)
The Addict
Upcoming Programmer Top Contributor 
 
Rendair's Avatar
 
Join Date: Nov 2007
Location: UK
Posts: 319
Thanks: 18
Rendair is on a distinguished road
Default

I would instead of imagestring use

PHP Code:
imagettftext($im2001020$black$font$text); 
This will give you more control over the font and how big it will be.

You can just put it directly onto the image without having to make a new image for each letter.


image An image resource, returned by one of the image creation functions, such as imagecreatetruecolor().

size The font size. Depending on your version of GD, this should be specified as the pixel size (GD1) or point size (GD2)

angle The angle in degrees, with 0 degrees being left-to-right reading text. Higher values represent a counter-clockwise rotation. For example, a value of 90 would result in bottom-to-top reading text.

x The coordinates given by x and y will define the basepoint of the first character (roughly the lower-left corner of the character). This is different from the imagestring(), where x and y define the upper-left corner of the first character. For example, "top left" is 0, 0.

y The y-ordinate. This sets the position of the fonts baseline, not the very bottom of the character.

color The color index. Using the negative of a color index has the effect of turning off antialiasing. See imagecolorallocate()

fontfile The path to the TrueType font you wish to use.
Depending on which version of the GD library PHP is using, when fontfile does not begin with a leading / then .ttf will be appended to the filename and the library will attempt to search for that filename along a library-defined font path.

text

__________________
www.jooney.co.uk - the online portfolio
Send a message via MSN to Rendair
Rendair is offline  
Reply With Quote
Old 04-26-2008, 09:37 PM   #3 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Thanks Dale, I made it work!



__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:35 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design