« on: December 02, 2007, 08:15:03 AM »
This tutorial will show you how to create a simple 468 x 60 banner online.
Form:<center>
<form name="cform" method="post" action="ini.php">
Title: <input style="border:1px solid; font-family:verdana; font-weight: bold" name="text" size="50"><br>
<br>
Line1: <input style="border:1px solid; font-family:verdana; font-weight:bold" name="text1" size="50"><br>
<br>
Line2: <input style="border:1px solid; font-family:verdana; font-weight:bold" name="text2" size="50"><br>
<br>
<INPUT TYPE="SUBMIT" name="submit" VALUE="Submit">
<INPUT TYPE="RESET" name="reset" VALUE="Reset">
</form>
</font>
</center>Get data from a form$textw = $_POST['text'];
$textw1 = $_POST['text1'];
$textw2 = $_POST['text2'];Font type $font = 'verdana.ttf';
$font1 = 'arial.ttf';Font size $fontsize = 28;
$fontsize1 = 8;
$fontsize2 = 9; Add the text $text = $textw; Text line 1$text1 = $textw1; Text line 2$text2 = $textw2;Box$box = imagettfbbox($fontsize, 0, $font, $text);
$box1 = imagettfbbox($fontsize1, 0, $font, $text1);
$box2 = imagettfbbox($fontsize2, 0, $font, $text2);Find out the width and height of the text box$xsize = abs($box[0]) + abs($box[2]);
$ysize = abs($box[1]) + abs($box[5]);
$xsize1 = abs($box1[0]) + abs($box1[2]);
$ysize1 = abs($box1[1]) + abs($box1[5]);
$xsize2 = abs($box2[0]) + abs($box2[2]);
$ysize2 = abs($box2[1]) + abs($box2[5]); Create the image - 468 x 60 for this example$image = imagecreatefrompng("image/bg1.png"); Get Image Size$imagesize = getimagesize("image/bg1.png"); Text position$positiona = round(($imagesize[0] - $xsize) / 2);
$positionb = round(($imagesize[1] + $ysize) / 2) ;
$positionaa = round(($imagesize[0] - $xsize) / 2);
$positionbb = round(($imagesize[1] + $ysize) / 2) - 3;
$positiona1 = round(($imagesize[0] - $xsize1) / 14);
$positionb1 = round(($imagesize[1] + $ysize1) / 4) - 3;
$positiona2 = round(($imagesize[0] - $xsize2) / 1) - 9;
$positionb2 = round(($imagesize[1] + $ysize2) / 2) + 14; Font color$color = ImageColorAllocate($image, 80, 80, 80); Shadow font color$color1 = ImageColorAllocate($image, 255,255,255);
imagettftext($image, $fontsize, 0, $positiona, $positionb, $color, $font, $text);Add some shadow to the title textimagettftext($image, $fontsize, 0, $positionaa, $positionbb, $color1, $font, $text);Text lines 1 and 2imagettftext($image, $fontsize1, 0, $positiona1, $positionb1, $color, $font1, $text1);
imagettftext($image, $fontsize2, 0, $positiona2, $positionb2, $color, $font1, $text2); ini.php<?php
// Get data from a form
$textw = $_POST['text'];
$textw1 = $_POST['text1'];
$textw2 = $_POST['text2'];
// Font type
$font = 'verdana.ttf';
$font1 = 'arial.ttf';
// Font size
$fontsize = 28;
$fontsize1 = 8;
$fontsize2 = 9;
// Add the text
$text = $textw;
// Text line 1
$text1 = $textw1;
// Text line 2
$text2 = $textw2;
//Box
$box = imagettfbbox($fontsize, 0, $font, $text);
$box1 = imagettfbbox($fontsize1, 0, $font, $text1);
$box2 = imagettfbbox($fontsize2, 0, $font, $text2);
//Find out the width and height of the text box
$xsize = abs($box[0]) + abs($box[2]);
$ysize = abs($box[1]) + abs($box[5]);
$xsize1 = abs($box1[0]) + abs($box1[2]);
$ysize1 = abs($box1[1]) + abs($box1[5]);
$xsize2 = abs($box2[0]) + abs($box2[2]);
$ysize2 = abs($box2[1]) + abs($box2[5]);
//Create the image - 468 x 60 for this example
$image = imagecreatefrompng("image/bg1.png");
//Get Image Size
$imagesize = getimagesize("image/bg1.png");
//Text position
$positiona = round(($imagesize[0] - $xsize) / 2);
$positionb = round(($imagesize[1] + $ysize) / 2) ;
$positionaa = round(($imagesize[0] - $xsize) / 2);
$positionbb = round(($imagesize[1] + $ysize) / 2) - 3;
$positiona1 = round(($imagesize[0] - $xsize1) / 14);
$positionb1 = round(($imagesize[1] + $ysize1) / 4) - 3;
$positiona2 = round(($imagesize[0] - $xsize2) / 1) - 9;
$positionb2 = round(($imagesize[1] + $ysize2) / 2) + 14;
///Font color
$color = ImageColorAllocate($image, 80, 80, 80);
/// Shadow font color
$color1 = ImageColorAllocate($image, 255,255,255);
imagettftext($image, $fontsize, 0, $positiona, $positionb, $color, $font, $text);
//// Add some shadow to the title text
imagettftext($image, $fontsize, 0, $positionaa, $positionbb, $color1, $font, $text);
// Text lines 1 and 2
imagettftext($image, $fontsize1, 0, $positiona1, $positionb1, $color, $font1, $text1);
imagettftext($image, $fontsize2, 0, $positiona2, $positionb2, $color, $font1, $text2);
header('content-type: image/png');
imagepng($image);
imagedestroy($image);
?>
« Last Edit: May 25, 2008, 04:07:11 PM by admin »

Logged