Ok, preliminary version of the script is available. I can't test it
yet, because I don't have access to any servers with all the required
pieces installed. I should have access to one middle of next week,
so if there's any problems, I should be able to iron them out then.
However, here's a quick rundown of how it works, and what it will do
for you.
The file can be downloaded at:
http://www.softcon.com/php/design.zip
In that file, you'll find two files.
the design_button.html is simply the file you load into the browser.
it will ask for the text you want on the icon.
When you press submit, it will pass the text to a php script called
make_button.php.
This is the piece that does all the work.
I couldn't remember what the required sizes were, so I just put
800x600. You'll need to change these to fit the apple requirements.
I'll of course take care of his when I post the final version, but
for now, those wishing to test it out will need to change these values.
The php code will start with the largest font it can use (33 point)
and decrease the font size down to the largest size that will still
fit into the size requirements of the icon.
After it finds a size that works, it will generate the jpg file, and
dump it to your browser. It does not create a file, or save the info
anywhere, so you'll need to rightclick on the image, and do a save as
to keep the generated file.
Since I'm unable to test this at this time, you may want to have
sighted assistance initially to verify everything worked. You'll
need gd version 1.8 on your webhost for this to work (gd is compiled
into php, so if you're not using the latest versions of all the
available software, it may not work for you)..
That's part of the problem. But, as I said, mid-next week, I should
have it up on a working server, and folks can just use that when they
need a nice graphical icon for their podcasts.
This code is a combination of code from php and mysql 3rd edition,
and the php manual. As mentioned above, it cannot be tested at this
time, but except for the image size, I expect it to work as
advertised. If someone does have all required software versions, and
it still doesn't behave properly, let me know, and I'll patch it to
the best of my ability until I can solve any issues myself upon
obtaining a new server for testing. I've got a Ubuntu box coming,
and I'll be able to solve any outstanding bugs when it arrives.
Any other questions, fel free to inbox me. hope this helps.
Just for reference, the files are pasted below, but you can also
download the pair from the url given above, and that is:
http://www.softcon.com/php/design.zip
*design_button.html*
**cut here**
<html>
<head>
<title>Create icons</title>
<head>
<body>
<h1>Create icons</h1>
<form method="post" action="make_button.php">
Type button text:<br />
<input type="text" name="button_text"><br /><br />
<input type="submit" value="Create icon">
</form>
</body>
</html>
**cut here**
And, now for the make_button.php file.
**cut here**
<?php
// check we have the appropriate variable data
// variable is button-text
$button_text = $_REQUEST['button_text'];
if (empty($button_text)
{
echo 'Could not create image - form not filled out correctly';
exit;
}
// create an image of the right background and check size
$im = imagecreatetruecolor(120, 20);
$width_image = 800;
$height_image = 600;
// Our images need an 18 pixel margin in from the edge of the image
$width_image_wo_margins = $width_image - (2 * 18);
$height_image_wo_margins = $height_image - (2 * 18);
// Work out if the font size will fit and make it smaller until it does
// Start out with the biggest size that will reasonably fit on our
buttons
$font_size = 33;
// you need to tell GD2 where your fonts reside
putenv('GDFONTPATH=/Library/Fonts');
$fontname = 'arial';
do
{
$font_size--;
// find out the size of the text at that font size
$bbox=ImageTTFBBox ($font_size, 0, $fontname, $button_text);
$right_text = $bbox[2]; // right co-ordinate
$left_text = $bbox[0]; // left co-ordinate
$width_text = $right_text - $left_text; // how wide is it?
$height_text = abs($bbox[7] - $bbox[1]); // how tall is it?
}
while ( $font_size>8 &&
( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
);
if ( $height_text>$height_image_wo_margins ||
$width_text>$width_image_wo_margins )
{
// no readable font size will fit on button
echo 'Text given will not fit on button.<br />';
}
else
{
// We have found a font size that will fit
// Now work out where to put it
$text_x = $width_image/2.0 - $width_text/2.0;
$text_y = $height_image/2.0 - $height_text/2.0 ;
if ($left_text < 0)
$text_x += abs($left_text); // add factor for left overhang
$above_line_text = abs($bbox[7]); // how far above the baseline?
$text_y += $above_line_text; // add baseline factor
$text_y -= 2; // adjustment factor for shape of our template
$white = ImageColorAllocate ($im, 255, 255, 255);
ImageTTFText ($im, $font_size, 0, $text_x, $text_y, $white,
$fontname,
$button_text);
Header ('Content-type: image/png');
ImagePNG ($im);
}
ImageDestroy ($im);
?>
**cut here**
That's all folks.
hth.
<--- Mac Access At Mac Access Dot Net --->
To reply to this post, please address your message to [email protected]
You can find an archive of all messages posted to the Mac-Access forum at
either the list's own dedicated web archive:
<http://mail.tft-bbs.co.uk/pipermail/mac-access/index.html>
or at the public Mail Archive:
<http://www.mail-archive.com/[email protected]/>.
Subscribe to the list's RSS feed from:
<http://www.mail-archive.com/[email protected]/maillist.xml>
As the Mac Access Dot Net administrators, we do our very best to ensure that
the Mac-Access E-Mal list remains malware, spyware, Trojan, virus and
worm-free. However, this should in no way replace your own security strategy.
We assume neither liability nor responsibility should something unpredictable
happen.
Please remember to update your membership preferences periodically by visiting
the list website at:
<http://mail.tft-bbs.co.uk/mailman/listinfo/mac-access/options/>