0

I'm on my way to create a new script for my personal website. I want some kind of function where visitors can write something in an input field and then press generate image.

The script should then take a background image and insert the visitors text on top.

My question is: What is the php code to actually generate the image file and how do i connect the input data to the image?

I do not need full code examples if you don't have the time, i just need the basis practice of how to setup such a system.

3
  • php.net/manual/en/book.imagick.php imagemagick.org check your phpinfo() maybe u have it installed. Rest is self explanatory Commented Apr 17, 2015 at 9:46
  • Stackoverflow does not do your work. You should show at least minimal self effort in trying to solve your problem. Commented Apr 17, 2015 at 10:59
  • I feel my question is fairly within those borders. I only asked for the basic setup of such system. The gentlemen simply provided some code. Commented Apr 17, 2015 at 20:48

2 Answers 2

2

Try this code:

$filename = "layout.jpg";

$im = @imagecreatefromjpeg($filename);
$font = "tahoma.ttf";

$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

imagettftext($im, 15, 0, 50, 50, $black, $font, $_POST['message_from_user']);

header('Content-Type: image/jpeg');

imagejpeg($im, null, 100);
imagedestroy($im);

layout.jpg is background image, tahoma.ttf is font file

Both files should be placed in the same folder.

This code would generate jpg-image with user string.

More details you would get by searching "gd in php".

Sign up to request clarification or add additional context in comments.

Comments

1

do something like this:

$text = 'put ur txt here'; 

$height = 25; 

$width = 65; 

$image_p = imagecreate($width, $height); 

$black = imagecolorallocate($image_p, 0, 0, 0); 

$white = imagecolorallocate($image_p, 255, 255, 255); 

$font_size = 14; 



imagestring($image_p, $font_size, 5, 5, $text, $white); 

imagejpeg($image_p, 'file name here', 80); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.