php image upload with adding text

369 Views Asked by At

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

There are 1 best solutions below

2
On

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?