S
S
sunmax2014-07-27 14:41:33
PNG
sunmax, 2014-07-27 14:41:33

How to generate an inscription on a picture?

I want to make an action: a person fills out a form (name, company) at the next step, a picture is generated in which the name of the company is substituted. The image must be printable.
How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Entelis, 2014-07-27
@sunmax

<?php
  //Set the Content Type
  header('Content-type: image/jpeg');

  // Create Image From Existing File
  $jpg_image = imagecreatefromjpeg('sunset.jpg');

  // Allocate A Color For The Text
  $white = imagecolorallocate($jpg_image, 255, 255, 255);

  // Set Path to Font File
  $font_path = 'font.TTF';

  // Set Text to Be Printed On Image
  $text = "This is a sunset!";

  // Print Text On Image
  imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

  // Send Image to Browser
  imagejpeg($jpg_image);

  // Clear Memory
  imagedestroy($jpg_image);
?>

www.phpforkids.com/php/php-gd-library-adding-text-...
php.net/manual/en/function.imagettftext.php
php.net/manual/en/function.imagestring.php

G
Grag, 2014-07-27
@Grag

Damn, there are a whole bunch of php libraries for this, just write “php image caption” in Google. You are not weak!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question