Jump to content

Adding text to an uploaded picture


raleagh

Recommended Posts

I have tried the following to add text to a picture that has been uploaded by a user.  The uploading works fine and creates a thumbnail.  The text generation works fine when i create a blank image and add text, but i can't get the two to work together. This is the part of the whole code that doesn't seem to work.

 

if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload')

{   // Uploading/Resizing Script

  $url = $_FILES['imagefile']['name'];   // Set $url To Equal The Filename For Later Use

 

  if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg")

  {

    $file_ext = strrchr($_FILES['imagefile']['name'], '.');   // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php

$newfilename = time().$file_ext;

$newthumbname = time().$file_ext;

$newfile = $idir . $newfilename;

$tmpfile = $_FILES['imagefile']['tmp_name'];

 

 

//put text on

$font = 'arial.tff';

 

// Create some colors

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

 

// The text to draw

$text = 'Testing...';

 

// Add some shadow to the text

imagettftext($tmpfile, 20, 0, 11, 21, $white, $font, $text);

 

 

imagejpeg($tmpfile);

 

//move uploaded picture to perm. folder

$copy = copy($tmpfile, $newfile);   // Move Image From Temporary Location To Permanent Location

    if ($copy) {   // If The Script Was Able To Copy The Image To It's Permanent Location

Link to comment
https://forums.phpfreaks.com/topic/111477-adding-text-to-an-uploaded-picture/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.