ultrus Posted September 13, 2006 Share Posted September 13, 2006 Hello,I recently started playing with the image creation in PHP. It's flipping awesome!I'm curious about fonts. For a visual reference, I want to list all of the installed fonts, each list item in thier own font, in a series of images to display on a page. How do I do this? Below are my initial scripting thoughts on this process. I would much appriciate any help filling in the blanks. Thank you! :)[code]<?php$numFonts = count("number of fonts"); //get the number of fonts somehow?for($i=0; $i<$numFonts; $i++) { $fontName = "font name"; //get font name? //folowing referenced from php.net - may not be what's needed for this project $im = imagecreatefrompng("images/background.png");[/code] Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted September 13, 2006 Share Posted September 13, 2006 why do it in image form? why not just export the plain text? Do you mean the client's installed fonts or the installed images on the server in the GD library?Seems like a lot of work for minimal reward. Quote Link to comment Share on other sites More sharing options...
ultrus Posted September 13, 2006 Author Share Posted September 13, 2006 Hi gerkintrigg,Thanks for the reply. This is the start of bigger projects. The fonts come from the server, not the client. One use would be creating custom images/text using live weather data to overlap webcam images, making the webcam "box" blend in better with the website design.Another application would be dynamic navigation menus in template systems.Dynamic page title graphics could be generated, keeping the design consistent, and not worrying about whether or not the client has the appripriate font installed. One of my designs uses title graphics at an angle. php text generation could be useful for that sort of thing.The image text could also be useful in cell phone gps systems. For example, I could have an image showing "Where is Ultrus", with stylized text saying "Ultrus is at work." over the map.Perhaps an ecard system could use this. The card sender can choose what font to use when sending a jpg card via email, and preview the image afterwards.Many possibilites. It's just hard for me not knowing what fonts are on my hosting service's server(s). Making a list would save me time, and give a visual reference. Quote Link to comment Share on other sites More sharing options...
zq29 Posted September 13, 2006 Share Posted September 13, 2006 To make a list of the available fonts, you would need to know where they are located on the server. As far as I'm aware there isn't a PHP function to list them. Unless you know of a command within the Operating System to list them, you could then execute that command with the exec() function.You can actually use your own True Type Fonts with GD, of which you can just create a directory in your webroot and throw your .ttf files in there and reference them in your script. You can use imagettftext() to select your fonts. If you were to go down this route, you could get a list off all your font files with the glob() function. Quote Link to comment Share on other sites More sharing options...
ultrus Posted September 13, 2006 Author Share Posted September 13, 2006 SemiApocalyptic,You rock! That helped me get on the right track. To show my appriciation, I have posted the working result below.I created a folder caled "fonts" on the server, made it writable, and uploaded some ttf fonts from my linux machine. The script creates a catalog of all the fonts in the folder with a file name below each image. If you can think of fun ways to enhance this, I'd love to see suggestions. Thanks for the great help![code]<?phpfunction showFonts($text, $dir) { $fontInt = 1; foreach (glob($dir . "*.ttf") as $filename) { $im = @imagecreate(450, 70) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 255, 255, 255); $text_color = imagecolorallocate($im, 0, 0, 0); $font = $filename; imagettftext($im, 30, 0, 10, 40, $text_color, $font, $text); $imgFile = "fonts/font" . $fontInt . ".png"; imagepng($im, $imgFile); imagedestroy($im); echo "<p><img src=$imgFile><br />$filename</p>\n\n"; $fontInt++; }}showFonts("This is way cool", "fonts/");?> [/code] Quote Link to comment Share on other sites More sharing options...
gerkintrigg Posted September 14, 2006 Share Posted September 14, 2006 Hmm sounds rather complicated. I understand why you'd need to look at the server's fonts... makes more sense than the client's. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.