Jump to content

Text to Image Submission questions


CocaCola
Go to solution Solved by DavidAM,

Recommended Posts

Hi guys, As you can tell I'm fresh and new here :tease-03: but I'm trying to learn PHP to do a few things that i need so i would truely appreciate any help or information and advice that i receive.

 

Basically what I'm trying to do is have two pages

 

First page consists of 5 text input boxes that have the fields.

 

Age

Name

Telephone

Skype

Address

Email

 

once these were filled out and a user hit Submit they would be generated onto a image for them to download. I'm having a few problems and searched the forum and did come across a thread that kind of explained to similar what i was trying to do but there wasn't much of a positive outcome or fix.

 

These input boxes need to be located at certain points of the image and not just anywhere. The first page where somebody would imput there data is :

<body>

<form name="code_input" enctype="application/x-www-form-urlencoded" method="GET" action="getcard.php">

Age: <input class="text" type="text" size="24" name="age" value="" />
<br>
Name: <input class="text" type="text" size="24" name="name" value="" />
<br>
Telephone: <input class="text" type="text" size="24" name="telephone" value="" />
<br>
Skype: <input class="text" type="text" size="24" name="skype" value="" />
<br>
Address: <input class="text" type="text" size="24" name="address" value="" />	
<br>
Email: <input class="text" type="text" size="24" name="email" value="" />	
<br>
	<input type="submit" name="submit" value="submit">
</form>

</body>
</html>

But i'm really not sure how i go about working 'getcard.php' page on the thread i found in the search this was something somebody had posted to generate text from a input page to a image.

<?php
	// Load the stamp and the photo to apply the watermark to
	$im = imagecreatefrompng('image.png');

	// Set the content-type
	header('Content-type: image/png');
	header("Content-Description: File Transfer");
	header("Content-Disposition: attachment; filename=coupon.png");
	header("Content-Transfer-Encoding: binary");

	$coupon_code = "empty code";
	
	if(isSet($_GET['coupon_code']))
	{
	   $coupon_code = $_GET['coupon_code'];
	}

	// Replace path by your own font path
	$font = 'arial.ttf';

	$black = ImageColorAllocate ($im, 0, 0, 0);
	$grey = ImageColorAllocate ($im, 128, 128, 128);
	
	// Add some shadow to the text
	imagettftext($im, 20, 0, 647, 351, $grey, $font, $coupon_code);

	// Add the text
	imagettftext($im, 20, 0, 646, 350, $black, $font, $coupon_code);

	// Using imagepng() results in clearer text compared with imagejpeg()
	imagepng($im);
?>

As i'm new I'm honestly not sure which direction to go now, I don't just want to copy and paste i would prefer to learn how but struggling to find any real helpful information in regarding what i require and how to do it.

 

Any advice/help/examples would truely be appreciated.

 

thanks alot

Link to comment
Share on other sites

  • Solution

 

	// Add some shadow to the text
	imagettftext($im, 20, 0, 647, 351, $grey, $font, $coupon_code);

	// Add the text
	imagettftext($im, 20, 0, 646, 350, $black, $font, $coupon_code);

 

These two lines put text on the image. The first one, according to the comment, is adding shadow text behind the actaul text. Have a look at imagettftext in the PHP manual for an explantaion of the parameters: image resource, position and size, color, font, text.
Link to comment
Share on other sites

Hi DavidAM,

 

Thanks for your post apprecaite it.

 

 

I've been reading on there and maybe i'm not understanding correctly but still seem to be having trouble.

 

I'm using this

<?php
// load the image from the file specified:
 
$im = imagecreatefrompng("warranty.png");
// if there's an error, stop processing the page:
if(!$im)
{
    die("");
}
// define some colours to use with the image
$black = imagecolorallocate($im, 80, 77, 77);

// get the width and the height of the image
$width = imagesx($im);

$height = imagesy($im);

// draw a black rectangle across the bottom, say, 20 pixels of the image:
//imagefilledrectangle($im, 0, ($height-20) , $width, $height, $black);
// now we want to write in the centre of the rectangle:
$font_size = 18;
$text = $_GET['text']; // store the text we're going to write in $text
putenv('GDFONTPATH=' . realpath('cour.ttf'));

// Name the font to be used (note the lack of the .ttf extension)
$font = 'cour';

// calculate the left position of the text:
$leftTextPos = ( $width - imagefontwidth($font)*strlen($text) )/2;

// finally, write the string:

imagestring($im,$font,$leftTextPos-210, $height-295,$text,$black);

 
// output the image
// tell the browser what we're sending it
Header('Content-type: image/png');
// output the image as a png
imagepng($im);
// tidy up
imagedestroy($im);
?>


But can't seem to be able to change the font face on the finished output.png

 

Any help

Edited by CocaCola
Link to comment
Share on other sites

 

putenv('GDFONTPATH=' . realpath('cour.ttf'));

 

Usually when an environment variable has PATH in the name, it contains ONLY the path (directory) not a full filename. Maybe try

 

putenv('GDFONTPATH=' . dirname(realpath('cour.ttf')));
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.