watermark as image

Started on the old forum in July 2009 · view the original in the archive · old links redirect here

9 replies · 1,005 views · started 17 years ago · 1 min read

7 participants
Vayne Developer · 106 posts #1

hola guys.. girls.. 🙂

anyone have script for watermarks who add image not text? at this moment i`ve text adder, but i've tried to change it for image adding to image, and no results..

help? 🙂

Nous Ne Dansos Pas, Nous Sommes Le Danse.!

GumSlone Administrator Principal · 1,690 posts #2
<?php  
header('content-type: image/jpeg');  

$watermark = imagecreatefrompng('watermark.png');  
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatefromjpeg('myimage.jpg');  
$size = getimagesize('myimage.jpg');  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);  

?>

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Anshul Senior · 296 posts #3

Vayne wrote: hola guys.. girls.. 🙂

anyone have script for watermarks who add image not text? at this moment i`ve text adder, but i've tried to change it for image adding to image, and no results..

help? :)

wud u post text adder watermarks ??

ori Lead · 512 posts #4

heres the text watermark from the thumbnail script i use

if ($_GET['txt'])
{
if ($_GET['c']) $watermark_color = $_GET['c'];
else $watermark_color = "000000";
$red = hexdec(substr($watermark_color,0,2));
$green = hexdec(substr($watermark_color,2,2));
$blue = hexdec(substr($watermark_color,4,2));
$text_col = imagecolorallocate($imw,$red,$green,$blue);
$font = "georgia.ttf";
$font_size = 12;
$angle = 0;
$box = imagettfbbox($font_size, $angle, $font, $_GET['txt']);
$x = 5;
$y = ImageSY($imw);
imagettftext($imw, $font_size, $angle, $x, $y, $text_col, $font, $_GET['txt']);
}
riderz Lead · 975 posts #5

make file watermark.php add this

<?php
// Images folder, must end with slash.
$images_folder = '/usergallery/';

// Save watermarked images to this folder, must end with slash.
$destination_folder = '/usergallery/';

// Path to the watermark image (apply this image as waretmark)
$watermark_path = '/images/saflag.png';

// MOST LIKELY YOU WILL NOT NEED TO CHANGE CODE BELOW

// Load functions for image watermarking
include("watermark_image.class.php");

// Watermark all the ".jpg" files from images folder
// and save watermarked images into destination folder
foreach (glob($images_folder."*.jpg") as $filename) {

  // Image path
  $image_path = $filename;

  // Where to save watermarked image
  $imgdestpath = $destination_folder . basename($filename);

  // Watermark image
  $img = new Zubrag_watermark($image_path);
  $img->ApplyWatermark($watermark_path);
  $img->SaveAsFile($imgdestpath);
  $img->Free();

}
?>

then make file called watermark_image.class.php

<?php  

#################################################################################
# Watermark Image Class 1.0
#################################################################################
# For updates visit http://www.zubrag.com/scripts/
#################################################################################
#
# REQUIREMENTS:
# PHP 4.0.6 and GD 2.0.1 or later
# May not work with GIFs if GD2 library installed on your server 
# does not support GIF functions in full
#
#################################################################################

class Zubrag_watermark {

  var $offset_x = 0;
  var $offset_y = 0;
  var $quality = 100;
  var $image_type = -1; // Image type: 1 = GIF, 2 = JPG, 3 = PNG
  var $force_image_type = -1; // Change image type? (-1 = same as original, 1 = GIF, 2 = JPG, 3 = PNG)
  var $save_to_file = true;

  function Zubrag_watermark($image_path='', $offset_x=0, $offset_y=0) {
    $this->setImagePath($image_path);
    $this->setOffset($offset_x, $offset_y);
  }

  function setImagePath($image_path) {
    $this->image_path = $image_path;
  }

  function setOffset($x, $y) {
    $this->offset_x = $x;
    $this->offset_y = $y;
  }

  function ImageCreateFromType($type,$filename) {
   $im = null;
   switch ($type) {
     case 1:
       $im = ImageCreateFromGif($filename);
       break;
     case 2:
       $im = ImageCreateFromJpeg($filename);
       break;
     case 3:
       $im = ImageCreateFromPNG($filename);
       break;
    }
    return $im;
  }

  function ApplyWatermark($watermark_path) {

    $this->watermark_path = $watermark_path;

    // Determine image size and type
    $size = getimagesize($this->image_path);
    $size_x = $size[0];
    $size_y = $size[1];
    $image_type = $size[2]; // 1 = GIF, 2 = JPG, 3 = PNG

    // load source image
    $image = $this->ImageCreateFromType($image_type, $this->image_path);

    // Determine watermark size and type
    $wsize = getimagesize($watermark_path);
    $watermark_x = $wsize[0];
    $watermark_y = $wsize[1];
    $watermark_type = $wsize[2]; // 1 = GIF, 2 = JPG, 3 = PNG

    // load watermark
    $watermark = $this->ImageCreateFromType($watermark_type, $watermark_path);

    // where do we put watermark on the image?
    $dest_x = $size_x - $watermark_x - $this->offset_x;
    $dest_y = $size_y - $watermark_y - $this->offset_y;

    imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_x, $watermark_y, 100);  

    $this->image = &$image;
    $this->watermark = &$watermark;
    $this->image_type = $image_type;

  } // ApplyWatermark

  function OutputImageInternal($filename='') {
 
    $im = &$this->image;
    $res = null;

    $image_type = ($this->force_image_type != -1 ? $this->force_image_type : $this->image_type);

    // ImageGIF is not included into some GD2 releases, so it might not work
    // output png if gifs are not supported
    if(($image_type == 1)  && !function_exists('imagegif')) $image_type = 3;

    switch ($image_type) {
      case 1:
        if ($this->save_to_file) {
          $res = ImageGIF($im,$filename);
        }
        else {
          header("Content-type: image/gif");
          $res = ImageGIF($im);
        }
        break;
      case 2:
        if ($this->save_to_file) {
          $res = ImageJPEG($im,$filename,$this->quality);
        }
        else {
          header("Content-type: image/jpeg");
          $res = ImageJPEG($im, NULL, $this->quality);
        }
        break;
      case 3:
        if (PHP_VERSION >= '5.1.2') {
          // Convert to PNG quality.
          // PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
          $quality = 9 - min( round($this->quality / 10), 9 );
          if ($this->save_to_file) {
            $res = ImagePNG($im, $filename, $quality);
          }
          else {
            header("Content-type: image/png");
            $res = ImagePNG($im, NULL, $quality);
          }
        }
        else {
          if ($this->save_to_file) {
            $res = ImagePNG($im, $filename);
          }
          else {
            header("Content-type: image/png");
            $res = ImagePNG($im);
          }
        }
        break;
    }
 
    return $res;
 
  }

  function Output($type = -1) {
    $this->force_image_type = $type;
    $this->save_to_file = false;
    $this->OutputImageInternal();
  }

  function SaveAsFile($filename, $type = -1) {
    $this->force_image_type = $type;
    $this->save_to_file = true;
    $this->OutputImageInternal($filename);
  }

  function Free() {
    imagedestroy($this->image);
    imagedestroy($this->watermark);
  }

}

?>

Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

archer Developer · 83 posts #6

Aww confusing

WAPMASTER ADD YOUR SITE AT TOPBEST AND GET 1000 UNIQUE VISIT PER DAY

riderz Lead · 975 posts #7

just create the 2 php files i said then it would work good


Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

i0nutzxp Developer · 150 posts #8

riderz wrote: just create the 2 php files i said then it would work good

ho ho ..to log that can be made by 1 function 🙂 short one 😕

<?php unlink('World/Europe/Romania.country'); ?>
riderz Lead · 975 posts #9

Hehe ok ionutz but thats the one im using


Jacques jacques@gw-designs.co.za http://coding.biz.tm Come join and lets make it a place to learn all the noobies how to code


NEVER FORGET TO CLICK THE TANX BUTTON IF U LIKE WHAT IM SHARING OR HELPING WITH

Vayne Developer · 106 posts #10

gumslone wrote:

<?php  
header('content-type: Image/jpeg');  

$watermark = imagecreatefrompng('watermark.png');  
$watermark_width = imagesx($watermark);  
$watermark_height = imagesy($watermark);  
$image = imagecreatefromjpeg('myimage.jpg');  
$size = getimagesize('myimage.jpg');  
$dest_x = $size[0] - $watermark_width - 5;  
$dest_y = $size[1] - $watermark_height - 5;  
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);  
imagejpeg($image);  
imagedestroy($image);  
imagedestroy($watermark);  

?>

спасибо ! 🙂)

Nous Ne Dansos Pas, Nous Sommes Le Danse.!

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