Jump to content

Watermarking image upon upload!


smonkcaptain

Recommended Posts

Hey all.

 

I'm Currently making an Upload form for my Aviation photography site.

 

Upon upload of the photo i want to embed a watermark. I really have no idea where to start, but here is my Upload.php script for the rest of the form:

 

<?php 
session_start(); 
$username=$_SESSION['username'];

//This is the directory where images will be saved 
$target = "upload/"; 
$target = $target .basename( $_FILES['photo']['name']); 

//This gets all the other information from the form 
$genre=$_POST['genre'];
$aircrafttype=$_POST['aircrafttype']; 
$airline=$_POST['airline']; 
$airport=$_POST['airport']; 
$country=$_POST['country'];
$registration=$_POST['registration'];
$connumber=$_POST['connumber'];
$day=$_POST['day'];
$month=$_POST['month'];
$year=$_POST['year'];
$remarks=$_POST['remarks']; 
$photo=($_FILES['photo']);

$date=$day.'-'.$month.'-'.$year;

foreach($_POST['tag'] as $tag){
   if($tag){
       $tags[] = $tag;
   }
}
$tag = implode('+',$tags);

// Connects to your Database 
mysql_connect("77.68.105.107", "jimmyleama2", "a340a340") or die(mysql_error()) ; 
mysql_select_db("jimmyleama2") or die(mysql_error()) ; 

//Writes the information to the database 
mysql_query("INSERT INTO `photographs` (`Username`, `Genre`, `Aircraft Type`, `Airline`, `Country`, `Airport/Airfield`, `Registration`,`Construction #`, `Category`, `Date`, `photo`, `Remarks`) VALUES ('$username', '$genre', '$aircrafttype', '$airline', '$country', '$airport', '$registration', '$connumber', '$tag', '$date', '$photo', '$remarks')")or die(mysql_error()); 

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{ 
   
//Tells you if its all ok 
echo "<center>Thankyou <strong>$username</strong> for your Upload. Your Photograph has been added to the Screening Queue. <br> Below are details of your Upload.</center>"; 
} 
else { 

//Gives and error if its not 
echo "Sorry, there was a problem uploading your file."; 
} 
?> 

 

Thankyou for your help, and if any more information is needed, just ask :D

 

Jimmy Leaman.

Link to comment
https://forums.phpfreaks.com/topic/206232-watermarking-image-upon-upload/
Share on other sites

This is a function I use for adding watermarks

function cr_jpg ($image_name){
    ini_set("memory_limit","512M");
    // ceate thumbnail with copyright
global $destination_path, $width, $where_temp, $where_temp2,$new_name; 
$dest_image="$new_name";
$image = imagecreatefromjpeg($where_temp2.$image_name);
$icon = ImageCreateFromPNG("watermark.png");
$width = ImageSX($icon);
$height = ImageSY($icon);
ImageCopyResized($image,$icon,0,0,0,0,$width,$height,$width,$height);
imagejpeg($image,$destination_path.$dest_image); 
ini_restore("memory_limit"); 
}

 

As you see some parameters are held in variables that are set outside of the function

 

Hope this helps

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.