Kvakond's Blog

Feb 14, 2009 10:31 AM
Yes you can! With this: Download

Introducing Kvakond's Justify Text On Image v.0.9


The package contains 2+2 mindblowingly awesome functions for your pleasure only! Download now and you get 20% extra code plus a chance to win a life-time membership!
Furthermore, the first 15 downloaders get 2 high-quality font files - totally free!

Justify.class.php:

2 support functions:
- 'calculateTextBox' takes any given string, "puts a box around it", and gives back the parameters of the box. Basically you can get the width, height, etc. of the string in pixels.
Pretty useful if you want to align text for example.

- 'wrap_limit' takes a string, tries to "put it in a box" that has a given width. It returns the number of characters that fit inside that box - basically it calculates a number that can be used with the 'wordwrap' function, so you can have an optimal text wrapping.

2 main functions:
- 'JustifyTextOnImage' takes the text string and an image, wraps the text using 'wrap_limit' (unless the $wraplimit parameter is set manually), and returns the image with the justified text on it. The $image must be created beforehand and its width must to be added manually with $image_width!

- 'JustifyTextOnImageFile' is basically the same thing, but instead of the actual image, the path to the imagefile must be added with $image_path. This function creates the image itself and it has an extra parameter to set whether or not keep alpha transparency on the image.

justify_example.php:
A short script to show how you can use the two main functions.
blackbox.jpg
verdana.ttf
journal.ttf

Important note: I don't know s**t about PHP, this was my first time writing anything on my own in PHP. I mean it's not even in a class, I just call the file class for fun and giggles. Because of this the code is far from elegant, optimized or bug-proof! But it works.. as far as I know. If you have any problems please let me know! If you know anything about PHP and you find bugs or ways to make the script better please let me know! That is all.
Posted by Kvakond | Feb 14, 2009 10:31 AM | 1 comments
kuroshiroi | Feb 14, 2009 11:26 AM
Thanks, it works great :)

Now all I need is an idea...
 
It’s time to ditch the text file.
Keep track of your anime easily by creating your own list.
Sign Up Login