toxic27 Posted June 14, 2009 Share Posted June 14, 2009 hey guys, i have this:<?$text = stripslashes($_GET['text']);header ("Content-type: image/png");$string = $text;$font = 2;$width = ImageFontWidth($font)* strlen($string) ;$height = ImageFontHeight($font) ;$im = ImageCreateFrompng("./gold.png");$x=imagesx($im)-$width ;$y=imagesy($im)-$height;$background_color = imagecolorallocate ($im, 255, 255, 255);$text_color = imagecolorallocate ($im, 255, 255, 255);imagestring ($im, $font, 52, 27, $string, $text_color);imagepng ($im);?>it pretty much just puts text on an image but i need to know how to change the font of the text (to like Arial or something). any help is appreciated! Link to comment Share on other sites More sharing options...
Synook Posted June 14, 2009 Share Posted June 14, 2009 I don't think any GD functions have uppercase in them...Anyway, the answer is to use the imagettftext() or imagepstext() functions (depending on what font you want to use). Bear in mind you need additional extensions for these to work. Link to comment Share on other sites More sharing options...
toxic27 Posted June 14, 2009 Author Share Posted June 14, 2009 I don't think any GD functions have uppercase in them...Anyway, the answer is to use the imagettftext() or imagepstext() functions (depending on what font you want to use). Bear in mind you need additional extensions for these to work.Yeah, I saw those but was confused. I didn't understand why you need extensions to get fonts for that but not to get fonts for other code (say for instance a <p>'s font).Anyways, what extensions do I need? Link to comment Share on other sites More sharing options...
Synook Posted June 14, 2009 Share Posted June 14, 2009 You need the FreeType library. It's because GD wasn't designed with text in mind, so it didn't include font handling natively.If you get fonts client-side then the browser handles it. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 14, 2009 Share Posted June 14, 2009 I didn't understand why you need extensions to get fonts for that but not to get fonts for other code (say for instance a <p>'s font).Because web browsers are configured to use certain fonts, and they use the OS's font system to render everything. The server needs a way to render the fonts also, so that's what the library does. The browser already has a way to render fonts.In addition to the library, you also need the font file. You'll find all the fonts that Windows uses in the Windows\fonts directory. Any file in there that ends with .ttf you can load using the truetype functions, such as imagettftext. You'll need to distribute the font files with your PHP script also. Link to comment Share on other sites More sharing options...
toxic27 Posted June 14, 2009 Author Share Posted June 14, 2009 I hate the learning process for PHP so much. lolWell, I downloaded the FreeType and put it on my server along with pulling a font from my computer (not sure if this is needed) and put it on my server.Now I changed the file that's trying to use it to this:<?$text = stripslashes($_GET['text']);header ("Content-type: image/png");$string = $text;$font = 2;$font_type = 'arial.ttf';$width = ImageFontWidth($font)* strlen($string) ;$height = ImageFontHeight($font) ;$im = ImageCreateFrompng("./gold.png");$x=imagesx($im)-$width ;$y=imagesy($im)-$height;$background_color = imagecolorallocate ($im, 255, 255, 255);$text_color = imagecolorallocate ($im, 255, 255, 255);imagettftext($im, $font, 0, $text_color, $font_type, $string);imagepng ($im);?>It still doesn't work. I really don't know what I'm doing wrong so help is appreciated.. again.Here's the link to the file: http://www.kingps3.com/ct/trophy.php?text=This%20is%20text!Oh, and as you can see at the URL, the image is being cancelled for some reason. The path for it is fine though Link to comment Share on other sites More sharing options...
justsomeguy Posted June 14, 2009 Share Posted June 14, 2009 Check the example, you're missing x and y coordinates:http://www.php.net/imagettftextAlso, you're giving it a size of "2". That's either in pixels or points, but either way that's really, really small. Link to comment Share on other sites More sharing options...
toxic27 Posted June 15, 2009 Author Share Posted June 15, 2009 Alright, cool, it's working now. Only problem is the picture is supposed to have rounded edges with transparent corners and it shows up as a black background. How would I make it transparent?Here's the image: http://www.kingps3.com/ct/trophy.php?type=...t%20descriction Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2009 Share Posted June 15, 2009 Check the comments on this page, there are several notes about it:http://www.php.net/manual/en/function.imagecreatefrompng.php Link to comment Share on other sites More sharing options...
toxic27 Posted June 15, 2009 Author Share Posted June 15, 2009 Nevermind, got it figured out. Had to repeat the function twice in the code; one for the picture and one for the text.Thanks for all the help guys! Couldn't of done it without you! Link to comment Share on other sites More sharing options...
toxic27 Posted June 15, 2009 Author Share Posted June 15, 2009 Oh, and one more minor thing. I'm wondering if it's possible to make the image come out as a .GIF or .PNG image instead of a .PHP image. It might help you if you actually check out the feautre thing I made. Would it be possible to make it a .GIF or .PNG image instead?The feature: http://www.kingps3.com/ct/main.php Link to comment Share on other sites More sharing options...
justsomeguy Posted June 15, 2009 Share Posted June 15, 2009 I don't know what you mean by a .php image, .php files are not images, they're code. You use the imagepng, imagejpeg, imagegif etc functions to output as various image types. The image you are outputting is a PNG image. Link to comment Share on other sites More sharing options...
toxic27 Posted June 16, 2009 Author Share Posted June 16, 2009 I don't know what you mean by a .php image, .php files are not images, they're code. You use the imagepng, imagejpeg, imagegif etc functions to output as various image types. The image you are outputting is a PNG image.Well, would there be away to turn that code into a .PNG image?The reason I'm looking to do this is because there is a site's forums I'm trying to make an embed code to and since the file (http://www.kingps3.com/ct/trophy.php?type=b&text=test) ends in .PHP, it doesn't allow it. How would I make it to .PNG or .GIF or whatever?If you need more info, just say.Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 16, 2009 Share Posted June 16, 2009 One way is to use htaccess to redirect requests for a certain PNG file to your PHP script. So even though the URL is pointing to a PNG file, it would actually be a PHP file that handles it on the server. For information about that, look up URL rewriting. Another way is set up the server to handle all PNG files as PHP files, but that's probably not the best idea. Link to comment Share on other sites More sharing options...
toxic27 Posted June 17, 2009 Author Share Posted June 17, 2009 Alright, is there a way to integrate PHP into the .htaccess file? The PHP file with the "image code" in it has some.. umm.. I forget what it is called. Here's an example:http://www.kingps3.com/ct/trophy.php?type=b&text=Text goes here!Whatever that is. I forgot what it is called haha. Yeah well is there a way to pass that info through the .htaccess file and to the actual .PHP "image code" file? Link to comment Share on other sites More sharing options...
Synook Posted June 17, 2009 Share Posted June 17, 2009 That's the querystring. You can capture it using RewriteCond, then use the %n variable to access it, e.g. RewriteCond %{QUERY_STRING} (.*) Link to comment Share on other sites More sharing options...
justsomeguy Posted June 17, 2009 Share Posted June 17, 2009 I don't use htaccess a lot, but it looks like all you really need to do is change the extension. So you would change this link:http://www.kingps3.com/ct/trophy.png?type=b&text=Text goes here!to this:http://www.kingps3.com/ct/trophy.php?type=b&text=Text goes here!Like I said, I haven't used htaccess a lot, but you should be able to find a lot of information online about working with it. Link to comment Share on other sites More sharing options...
toxic27 Posted June 19, 2009 Author Share Posted June 19, 2009 Alright, thanks, is there anyway you could write it for me? I know it sounds lazy but I literally searched all over Google for more on this and nothing worked.All I need is for 'http://www.kingps3.com/ct/trophy.png?type=b&text=abcdef' to be redirected to this 'http://www.kingps3.com/ct/trophy.php?type=b&text=abcdef'.BTW, justsomeguy, that wouldn't work because the variable changes everytime. It's for a feature that users on my site can use in which they pick what the 'text=' equals so I couldn't just put one statement (like 'Text goes here!') for it.Thanks for helping guys Link to comment Share on other sites More sharing options...
toxic27 Posted June 21, 2009 Author Share Posted June 21, 2009 Or can someone lead me to a site explaining it? thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted June 22, 2009 Share Posted June 22, 2009 http://www.google.com/search?q=htaccess+re...-8&oe=utf-8 Link to comment Share on other sites More sharing options...
skaterdav85 Posted July 31, 2009 Share Posted July 31, 2009 I hate the learning process for PHP so much. lolWell, I downloaded the FreeType and put it on my server along with pulling a font from my computer (not sure if this is needed) and put it on my server.Now I changed the file that's trying to use it to this:<?$text = stripslashes($_GET['text']);header ("Content-type: image/png");$string = $text;$font = 2;$font_type = 'arial.ttf';$width = ImageFontWidth($font)* strlen($string) ;$height = ImageFontHeight($font) ;$im = ImageCreateFrompng("./gold.png");$x=imagesx($im)-$width ;$y=imagesy($im)-$height;$background_color = imagecolorallocate ($im, 255, 255, 255);$text_color = imagecolorallocate ($im, 255, 255, 255);imagettftext($im, $font, 0, $text_color, $font_type, $string);imagepng ($im);?>It still doesn't work. I really don't know what I'm doing wrong so help is appreciated.. again.Here's the link to the file: http://www.kingps3.com/ct/trophy.php?text=This%20is%20text!Oh, and as you can see at the URL, the image is being cancelled for some reason. The path for it is fine thoughIn this example, is 'arial.ttf' in the same directory as this script? When you download fonts, do they come in .ttf files? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.