Jump to content


Photo

Text to Image Submission questions


Best Answer DavidAM, 05 May 2013 - 08:56 AM

	// 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. Go to the full post


  • Please log in to reply
3 replies to this topic

#1 CocaCola

CocaCola

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 05 May 2013 - 07:40 AM

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



#2 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,972 posts
  • LocationSpring, TX USA

Posted 05 May 2013 - 08:56 AM   Best Answer

	// 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.
-- I haven't lost my mind, it's backed up on tape ... somewhere!

#3 CocaCola

CocaCola

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 05 May 2013 - 10:26 AM

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, 05 May 2013 - 10:33 AM.


#4 DavidAM

DavidAM

    Advanced Member

  • Gurus
  • 1,972 posts
  • LocationSpring, TX USA

Posted 05 May 2013 - 10:01 PM

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')));

-- I haven't lost my mind, it's backed up on tape ... somewhere!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com