Jump to content

watermark


fullyloaded

Recommended Posts

hi
i have this watermark code that works great but it will only do one image i was wondering if there is away to change this coding to do all the images in a folder here is the code thanks...
[code]<?
include  ("watermark.php");
$iw = new imageWaterMarker();
$iw->image_location = 'test.jpg';
$iw->image_type = 'jpeg';
$iw->size = 1;  //This could be any value from 1 to 5
$iw->copyright_text = '(C) 2004 : here';
$iw->markImage();
?>[/code]

[code]<?
class imageWaterMarker
{
var $image_location;
var $copyright_text;
var $image_type;
var $size =1;

function markImage()
{
$img = GetImageSize($this->image_location);
$width = $img[0];
$height = $img[1];
switch ($this->image_type)
{
case 'jpg':
case 'jpeg':
//Here is JPG Loader
$im2 = imagecreatefromjpeg($this->image_location);
//End JPG loader
//Now JPG Text Color Change Tricks
$im = imagecreate($width,$height);
imagecopy($im,$im2,0,0,0,0,$width,$height);
//End Trick
break;

case 'png':
$im = imagecreatefrompng($this->image_location);
break;
}
$black = imagecolorallocate($im,0,32,234);
//$black = imagecolorallocate($im,12,132,34);
imagestring($im,$this->size,0,$height-30,$this->copyright_text,$black);
header ("Content: image/png");
imagepng($im);

}
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/30557-watermark/
Share on other sites

the preg_ls function was taken from here:

http://us3.php.net/manual/en/class.dir.php#60562

[code]<?php
function preg_ls ($path=".", $rec=false, $pat="/.*/") {
  // it's going to be used repeatedly, ensure we compile it for speed.
  $pat=preg_replace("|(/.*/[^S]*)|s", "\\1S", $pat);
  //Remove trailing slashes from path
  while (substr($path,-1,1)=="/") $path=substr($path,0,-1);
  //also, make sure that $path is a directory and repair any screwups
  if (!is_dir($path)) $path=dirname($path);
  //assert either truth or falsehoold of $rec, allow no scalars to mean truth
  if ($rec!==true) $rec=false;
  //get a directory handle
  $d=dir($path);
  //initialise the output array
  $ret=Array();
  //loop, reading until there's no more to read
  while (false!==($e=$d->read())) {
      //Ignore parent- and self-links
      if (($e==".")||($e=="..")) continue;
      //If we're working recursively and it's a directory, grab and merge
      if ($rec && is_dir($path."/".$e)) {
          $ret=array_merge($ret,preg_ls($path."/".$e,$rec,$pat));
          continue;
      }
      //If it don't match, exclude it
      if (!preg_match($pat,$e)) continue;
      //In all other cases, add it to the output array
      $ret[]=$path."/".$e;
  }
  //finally, return the array
  return $ret;
}

$pictures = preg_ls("/path/to/pictures/");

foreach ($pictures as $picture) {
$iw = new imageWaterMarker();
$iw->image_location = 'test.jpg';
$iw->image_type = 'jpeg';
$iw->size = 1;  //This could be any value from 1 to 5
$iw->copyright_text = '(C) 2004 : here';
$iw->markImage();
$iw = "";
}
?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/30557-watermark/#findComment-140682
Share on other sites

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.