I want to add watermark png image below is my multiple image upload code that store images in database.
This code worked is worked fine for simple image upload for multiple upload. I just want to add water mark while it upload. also it stores in database.
<?php
ob_start();
session_start();
include("includes/include_all.php");
include("includes/validation.php");
include("resize-class.php");
if(isset($_POST) && $_SERVER['REQUEST_METHOD'] == "POST")
$rand=rand(1000,9999);
$vpb_file_name = $rand.strip_tags($_FILES['upload_file']['name']); //File Name
$vpb_file_id = strip_tags($_POST['upload_file_ids']); // File id is gotten from the file name
$vpb_file_size = $_FILES['upload_file']['size']; // File Size
$vpb_uploaded_files_location = '../upload/gallery_photo/'; //This is the directory where uploaded files are saved on your server
$vpb_final_location = $vpb_uploaded_files_location . $vpb_file_name; //Directory to save file plus the file to be saved
$ses_album_id = $_SESSION["session_album_id"];
//With Validation and saves filenames in the database
$vpb_file_extensions = pathinfo($vpb_file_name, PATHINFO_EXTENSION); // File Extension
$vpb_allowed_file_extensions = array("jpg","jpeg","gif","png"); //Allowed file types
$vpb_maximum_allowed_file_size = 3072*3072; // 1MB - You may change the maximum allowed upload file size here if you wish
//Validation for File Type
//Validation for File Size
if($vpb_file_size > $vpb_maximum_allowed_file_size)
{
//Display file size error error
echo 'file_size_error&'.$vpb_file_name;
}
else
{
if(move_uploaded_file(strip_tags($_FILES['upload_file']['tmp_name']), $vpb_final_location))
{
// Include the database connection setting file
//include "config.php";
$thumbpath = "../upload/gallery_photo/thumb/".$vpb_file_name;
$resizeObj = new resize($vpb_final_location);
$resizeObj -> resizeImage(140,100, 'crop');
$resizeObj -> saveImage($thumbpath, 100);
// Check for existing file
$check_existing_file = mysql_query("select * from photo_gallery where `file_id` = '".mysql_real_escape_string($vpb_file_id)."'");
if(mysql_num_rows($check_existing_file) < 1)
{
//Save this file because it does not already exist in the database table
if(mysql_query("insert into photo_gallery(album_id,file_id,file_name)
values('$ses_album_id','".mysql_real_escape_string($vpb_file_id)."', '".mysql_real_escape_string($vpb_file_name)."')"))
{
//Display the file id
echo $vpb_file_id;
}
else
{
//Display general system error
echo 'general_system_error';
}
}
else
{
// Do not save file because it already exist in the database
//Display the file id
echo $vpb_file_id;
}
}
else
{
//Display general system error
echo 'general_system_error';
}
}
}
?>
I have a below code but I dont know how to use this code.
$stamp = imagecreatefrompng('watermark.png');
// Set the margins for the stamp and get the height/width of the stamp image
$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
// Copy the stamp image onto our photo using the margin offsets and the photo
// width to calculate positioning of the stamp.
imagecopy($vpb_file_name, $stamp, imagesx($vpb_file_name) - $sx - $marge_right, imagesy($vpb_file_name) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp));
Aucun commentaire:
Enregistrer un commentaire