alright, there are three files, and the code is not very optimized or completely organized yet, so I hope you can understand it. FYI, this is for a site I will be making for a stamp company that allows customers to type what they want in the stamp, fonts, sizes, colors, alignment, etc. and the program will put it in the proper mount size and preview it. There will be many more options soon, but I find it hard to continue with this annoying issue. Anyway, here are the files. If you want to run the code, you will need to make a "fonts" folder in the same directory as the php files and put in at least one font named swiss.ttf (plus swissitalic, swissbold, and swissbolditalic for bold and italic fonts to work). Again, thanks for your time.
index.php:
<?php
include('draw.php');
include('mounts.php');
$mount=$selfinking;
$fontface='Swiss';
$fontsize=9;
$linespace=90;
$fontstyle=$bold . $italic;
draw($mount, $message, $fontface, $fontsize, $fontstyle, $linespace, $color, $align);
?>
<html>
<body bgcolor=000000 text=dd0000>
<center>
<img src="preview.gif">
<form method=post action="INDEX.php">
<table border=0><tr><td>
<table border=0><tr><td align=center colspan=3>
Alignment:</td></tr>
<tr><td align=center>Left<br>
<input type=radio name=align value=left <? if($align=='left') echo 'checked'; ?>></td>
<td align=center>Center<br>
<input type=radio name=align value=center <? if($align=='center') echo 'checked'; ?>></td>
<td align=center>Right<br>
<input type=radio name=align value=right <? if($align=='right') echo 'checked'; ?>>
</td></tr></table></td>
<td>
Color:<br>
<select name=color>
<option value=black <? if($color=='black') echo 'selected'; ?>>Black
<option value=blue <? if($color=='blue') echo 'selected'; ?>>Blue
<option value=red <? if($color=='red') echo 'selected'; ?>>Red
<option value=purple <? if($color=='purple') echo 'selected'; ?>>Purple
<option value=green <? if($color=='green') echo 'selected'; ?>>Green
</select></td>
<td>Font:<br>
<b>Bold</b><input type=checkbox name=bold value=bold
<? if($bold=='bold') echo 'checked'; ?>><br>
<i>Italic</i><input type=checkbox name=italic value=italic
<? if($italic=='italic') echo 'checked'; ?>></td></tr></table>
<p>
Line 1:<input type=text name="message[]" value="<? echo $message[0]; ?>"><br>
Line 2:<input type=text name="message[]" value="<? echo $message[1]; ?>"><br>
Line 3:<input type=text name="message[]" value="<? echo $message[2]; ?>"><br>
Line 4:<input type=text name="message[]" value="<? echo $message[3]; ?>"><br>
Line 5:<input type=text name="message[]" value="<? echo $message[4]; ?>"><p>
<input type="submit" value="Preview">
</form>
</body>
</html>
END OF FILE
mounts.php
<?php
$selfinking=array(
array(
'name' => 'SI-1',
'height' => .5,
'width' => 1.5,
'price' => 14.95
),
array(
'name' => 'SI-1.5',
'height' => .5,
'width' => 2.75,
'price' => 16.95
),
array(
'name' => 'SI-2',
'height' => .75,
'width' => 1.875,
'price' => 16.50
),
array(
'name' => 'SI-3',
'height' => .875,
'width' => 2.375,
'price' => 18.50
),
array(
'name' => 'SI-3.5',
'height' => 1,
'width' => 2.625,
'price' => 21.95
));
?>
END OF FILE
Draw.php:
<?php
function draw($mount, $message, $fontface, $fontsize, $fontstyle, $linespace, $color, $align)
{
$linespacing=$linespace/100;
$font="fonts/" . "$fontface" . "$fontstyle" . ".ttf";
$messagewidth=0;
$messageheight=0;
$charheight=imagettfbbox($fontsize,0,$font, 'A');
//count lines and chop off empty ones
$messagelines=0;
foreach($message as $a){
if($a!='') $messagelines++;
else if($delete>0) $messagelines--;
}
$message=array_slice ($message,0,$messagelines);
//get message height and width
if($message!=''){
foreach($message as $a){
$box=imagettfbbox($fontsize,0,$font, $a);
$messageheight+=$fontsize1.25$linespacing;
if($messagewidth<$box[2])
$messagewidth=$box[2];
}}
//set mount size
for($mountsize=0;$messagewidth>$mount[$mountsize][width]72 || $messageheight>$mount[$mountsize][height]72;$mountsize++){
if($mountsize>40) break;
}
$imgheight=($mount[$mountsize][height]72)+16;
$imgwidth=($mount[$mountsize][width]72)+16;
$im =imagecreate($imgwidth, $imgheight);
$colors=array(
grey=>imagecolorallocate($im, 175, 175, 175),
red=>imagecolorallocate($im, 255 , 0, 0),
green=>imagecolorallocate($im, 0, 175, 25),
blue=>imagecolorallocate($im, 0, 0, 255),
purple=>imagecolorallocate($im, 100, 0, 100),
black=>imagecolorallocate($im, 0, 0, 0),
white=>imagecolorallocate($im, 255, 255, 255)
);
imagefill($im, 0, 0, $colors[grey]);
imagefilledrectangle($im, 8, 8, $imgwidth-8, $imgheight-8, $colors[white]);
$x=0;
$y=((($imgheight-$messageheight)/2)-$fontsize1.25$linespacing)-$charheight[5];
if ($align=='center'){
imagettftext($im,8,0,3,7,$colors[black],$font,$mount[$mountsize][name]);
foreach($message as $a){
$y+=$fontsize1.25$linespacing;
$box=imagettfbbox($fontsize,0,$font, $a);
$x=($imgwidth-$box[2])/2;
imagettftext($im,$fontsize,0,$x,$y,$colors[$color],$font,$a);
}
}
if ($align=='left'){
imagettftext($im,8,0,3,7,$colors[black],$font,$mount[$mountsize][name]);
foreach($message as $a){
$y+=$fontsize1.25$linespacing;
$x=($imgwidth-$messagewidth)/2;
imagettftext($im,$fontsize,0,$x,$y,$colors[$color],$font,$a);
}
}
if ($align=='right'){
imagettftext($im,8,0,3,7,$colors[black],$font,$mount[$mountsize][name]);
foreach($message as $a){
$y+=$fontsize*1.25*$linespacing;
$box=imagettfbbox($fontsize,0,$font, $a);
$x=$messagewidth-$box[2]+(($imgwidth-$messagewidth)/2);
imagettftext($im,$fontsize,0,$x,$y,$colors[$color],$font,$a);
}
}
imagegif($im, 'preview.gif');
imagedestroy($im);
}
?>
END OF FILE