Hi guys,
i am going on with a vigorous practice with PHP and MYsQL. currently i am doing a simple project which has a form, input box which takes the users name, then selects a random image and place it on the image with a random selection of fonts, with a little of opacity so that the text blends to the image.

i think its a pretty tough one, but if some great teacher can teach me ill be very happy, to be a loyal student of that person.

How far have you got already? Show your code.

dis is on myimpage.php page

// array of random quotes
$quotes = array(
"VINAY",
"SAMEER",
"CHANDHU");

// generate a random number with range of # of array elements
$pos = rand(0,count($quotes)-1);
// get the quote and word wrap it
$quote = wordwrap($quotes[$pos]);

// create a bounding box for the text
$dims = imagettfbbox($fontsize, 0, $font, $quote);

// Create image
$image = imagecreatefromjpeg ( "Colorful.jpg" );

// pick color for the background
$bgcolor = imagecolorallocate($image, 100, 100, 100);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);

// x,y coords for imagettftext defines the baseline of the text: the lower-left corner
// so the x coord can stay as 0 but you have to add the font size to the y to simulate
// top left boundary so we can write the text within the boundary of the image
$x = 200; 
$y = ($fontsize);
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $quote);

// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);

// delete the image resource 
imagedestroy($image);

on the html page :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<img src="myimpage.php" width="764" height="429">
</body>
</html>

And where is the problem?

the font is not getting merged with the image and image randomization is not happening. also the position of the text is also not random

Where do you define $font and $fontsize?

$font = 'almonte.ttf';
$fontsize = 250;

// array of random quotes
$quotes = array(
"VINAY",
"SAMEER",
"CHANDHU");

// generate a random number with range of # of array elements
$pos = rand(0,count($quotes)-1);
// get the quote and word wrap it
$quote = wordwrap($quotes[$pos]);

// create a bounding box for the text
$dims = imagettfbbox($fontsize, 0, $font, $quote);

// Create image
$image = imagecreatefromjpeg ( "Colorful.jpg" );

// pick color for the background
$bgcolor = imagecolorallocate($image, 100, 100, 100);
// pick color for the text
$fontcolor = imagecolorallocate($image, 255, 255, 255);

// x,y coords for imagettftext defines the baseline of the text: the lower-left corner
// so the x coord can stay as 0 but you have to add the font size to the y to simulate
// top left boundary so we can write the text within the boundary of the image
$x = 200; 
$y = ($fontsize);
imagettftext($image, $fontsize, 0, $x, $y, $fontcolor, $font, $quote);

// tell the browser that the content is an image
header('Content-type: image/png');
// output image to the browser
imagepng($image);

// delete the image resource 
imagedestroy($image);

sorry had forgotten top two lines to be added..........................

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.