simple watermark script

Started on the old forum in March 2012 · view the original in the archive · old links redirect here

7 replies · 2,188 views · started 14 years ago · 1 min read

6 participants
GumSlone Administrator Principal · 1,690 posts #1

sometimes its easier and faster to add a watermark with php script than with a image editing software,

here is a very simple script which adds watermarks to your images:

copy the php code below and upload it to your site,

create a transparent png watermark image wm.png and upload it to the same directory as the script below.

in the script directory create a subdirectory "upload" and chmod 0777 the upload directory.

<?php
 if ((($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/jpeg")
 || ($_FILES["file"]["type"] == "image/pjpeg"))
 && ($_FILES["file"]["size"] < 900000))
   {
   if ($_FILES["file"]["error"] > 0)
     {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
     }
   else
     {
     
           $file_name = 'upload/'.substr(md5(time()),0,10).'.jpg';
           $file = imagecreatefromjpeg($_FILES["file"]["tmp_name"]);
           
           $watermark = @imagecreatefrompng('./wm.png');
           $imagewidth = imagesx($file);
           $imageheight = imagesy($file);
           $watermarkwidth = imagesx($watermark);
           $watermarkheight = imagesy($watermark);
           $startwidth = (($imagewidth - $watermarkwidth)/1);
           $startheight = (($imageheight - $watermarkheight)/1);
           imagecopy($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
           #imagecopymerge($file, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight, 80);
            imagedestroy($watermark);
           
           imagejpeg($file, $file_name, 90);
           ImageDestroy($new);
           ImageDestroy($file);     
     
     #echo "Upload: " . $_FILES["file"]["name"] . "<br />";
     #echo "Type: " . $_FILES["file"]["type"] . "<br />";
     #echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
     #echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
	echo '<img src="'.$file_name.'" alt=""/>';
     /*if (file_exists("upload/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
       }*/
     }
   }
 else
   {
   echo "Invalid file";
   }
 ?>
<html>
 <body>

 <form action="" method="post"
 enctype="multipart/form-data">
 <label for="file">File:</label>
 <input type="file" name="file" id="file" /> 
 <br />
 <input type="submit" name="submit" value="Submit" />
 </form>

 </body>
 </html>
 
<?php
if ($handle = opendir('./upload/')) {
    while (false !== ($entry = readdir($handle))) {
        if ($entry != "." && $entry != "..") {
            echo "<a href=\"upload/$entry\">$entry</a>, \n";
        }
    }
    closedir($handle);
}
?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Junkle Junior · 21 posts #2

tanx man..uzeful. pleaze can u upload it in zip file for download?

12345xmen Developer · 239 posts #4

how its wrk when some use img bbcode..its put watermark on image of not

ya its just for upload image watermark

akela Senior · 305 posts #5

video watermark scripts

External image (may be gone) Unlimited Web Hosting service. 99.99 $ uptime Guarantee. Free Trail Available for 30 days. Free Script | Null script| Php | Unlimited Web Hosting| Unlimited Space | Unlimited Bandwidth| Unlimited Domain| $3/m Unlimited Space | Unlimited Bandwidth|5 Domain| $2/m 10 GB Space | 100 GB Bandwidth| 1 Domain| $1/m FFMPEG| FREE SCRIPT | FREE SITE BUILDER |LIVE SUPPORT [Timewebhosting.com On Web Hosting| Unlimited Web Hosting](http://www…

just_m3. Developer · 199 posts #6

Do you guys have any watermark script that is able to addapt the background and switch color ? like for example if background is darker use white watermark ? i know i have had found a class some time ago but i lost its tracks .

This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!

GumSlone Administrator Principal · 1,690 posts #7

just_m3. wrote: Do you guys have any watermark script that is able to addapt the background and switch color ? like for example if background is darker use white watermark ? i know i have had found a class some time ago but i lost its tracks .

this might help you: http://stackoverflow.com/questions/10290259/detect-main-colors-in-an-image-with-php

👍 1
Share

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close