-1

I created an uploader for myself, now what I am trying is adding text on it too. I already created it outside the uploader but I just can't combine them two, already tried multiple sequences but failed :( need help here's the code.!

Here is the upload code.

$file_name = $_FILES[attach][name];
$caption=$_POST["caption"];
$uploaddir = "../photos";
$up_path=$uploaddir."/".$file_name;
move_uploaded_file($_FILES['attach']['tmp_name'], $up_path);

Here's the text on img code:

$get_image = imagecreatefromjpeg('name.jpg');
$white = imagecolorallocate($get_image, 255, 255, 255);
$txt = "Hello World";
$font = "arial.ttf"; 
imagettftext($get_image, 24, 0, 5, 24, $white, $font, $txt);
header('Content-type: image/jpeg');
imagejpeg($get_image, "name.jpg", 100);
imagedestroy($get_image);
04FS
  • 5,660
  • 2
  • 10
  • 21
Afridi
  • 25
  • 6
  • Please always show what you tried. _“Here's the text on img code:”_ - that uses `name.jpg` in two places - so which parts could possibly need replacing …? You _know_ where you just moved the uploaded file to, `$up_path`. (Whether it _needs_ moving could be discussed here, you could probably just work with `$_FILES['attach']['tmp_name']` as the input file instead.) – 04FS Dec 05 '19 at 08:36

1 Answers1

1

You can achieve watermarking using image libraries. You can find examples here.

Add 'Watermark' to images with php

An alternative way is to use FFMPEG Library which can be executed through php exec() method. See the link below.

How to add transparent watermark in center of a video with ffmpeg?

Jahan zeb
  • 21
  • 1
  • i just saw the code, but looks like it can add pictures only, i am trying to add the caption of the photos, – Afridi Dec 05 '19 at 07:34
  • You can create a bitmap of the caption text with alpha channel and add it as a picture/bitmap – Jahan zeb Dec 05 '19 at 10:26