My Idea is to upload a image file that is combined with a watermark. This code needs to work like this. On a portfolio website, the owner uploads an image he wants to sell throught the CMS i made. But because he wants to sell the image he wants it to come on the site with a watermark.
So my idea, i let him upload the original image, then i get the image through the $_Files() en combine it with a watermark, make it one image again and upload that image.
Now is my question, how do i upload a image created in PHP i tried to convert it to Base64 but with no luck. Here is my code.
Sorry for the bad english!
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$filetype = substr($target_file, -4);
if($filetype == ".gif") $image = @imagecreatefromgif($_FILES["fileToUpload"]["tmp_name"]);
if($filetype == ".jpg") $image = @imagecreatefromjpeg($_FILES["fileToUpload"]["tmp_name"]);
if($filetype == ".png") $image = @imagecreatefrompng($_FILES["fileToUpload"]["tmp_name"]);
if (empty($image)) die();
$watermark = @imagecreatefrompng('watermark.png');
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
$watermarkwidth = imagesx($watermark);
$watermarkheight = imagesy($watermark);
$startwidth = (($imagewidth - $watermarkwidth)/2);
$startheight = (($imageheight - $watermarkheight)/2);
imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
file_put_contents($target_file, $image)
imagejpegshould do the trick -> php.net/manual/en/function.imagejpeg.php (instead offile_put_contents)move_uploaded_filefirst to "upload" the file to a temp folder, then manipulate it however you need, then save it to its final location.move_uploaded_file, because the file is already in a temporary directory. but if the OP want's to save the original file he should use it to save the image on the server in addition to the watermarked one.