FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Need help with watermarks





Gitesh
I m working on elgg but unable to get any response there in forums so need help.

What will be the code to place in the watermark.php to achiveve below effect of watermark.,

Just need contrasting background with text over it so that its below image and is visible too.

Also need the watermark to be permanent as present plugin dont show watermark in downloaded image.

Below is the riginal code., Unable to attain this after several attempts.



The original code is given below., please let know what changes in it will acheive above watermark.

Quote:
Code:
<?php

function tp_process_watermark_text($text, $owner) {
   global $CONFIG;

   $text = str_replace("%name%", $owner->name, $text);
   $text = str_replace("%sitename%", $CONFIG->sitename, $text);
   
   return $text;
}

function tp_get_watermark_filename($text, $owner) {
   global $CONFIG;

   $base = strtolower($text);
   $base = preg_replace("/[^\w-]+/", "-", $base);
   $base = trim($base, '-');
   
   $filename = tp_get_img_dir();
   $filename .= strtolower($owner->username . "_" . $base . "_stamp");
   
   return $filename;
}

function tp_gd_watermark($image) {
   $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
   if (!$watermark_text)
      return;
   
   // plugins can do their own watermark and return false to prevent this function from running
   if (trigger_plugin_hook('tp_watermark', 'gd', $image, true) === false)
      return;
   
   global $CONFIG;
      
   $owner = get_loggedin_user();

   $watermark_text = tp_process_watermark_text($watermark_text, $owner);
      
   // transparent gray
   imagealphablending($image, true);
   $textcolor = imagecolorallocatealpha($image, 50, 50, 50, 60);
   
   // font and location
   $font = $CONFIG->pluginspath . "tidypics/fonts/LiberationSerif-Regular.ttf";
   $bbox = imagettfbbox(20, 0, $font, $watermark_text);
   
   $text_width = $bbox[2] - $bbox[0];
   $text_height = $bbox[1] - $bbox[7];
   
   $image_width = imagesx($image);
   $image_height = imagesy($image);
   
   $left = $image_width / 2 - $text_width / 2;
   $top = $image_height - 20;
   
   // write the text on the image
   imagettftext($image, 20, 0, $left, $top, $textcolor, $font, $watermark_text);
}

function tp_imagick_watermark($filename) {

   $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
   if (!$watermark_text)
      return;
   
   // plugins can do their own watermark and return false to prevent this function from running
   if (trigger_plugin_hook('tp_watermark', 'imagick', $filename, true) === false)
      return;
   
   $owner = get_loggedin_user();

   $watermark_text = tp_process_watermark_text($watermark_text, $owner);
   
    $img = new Imagick($filename);

    $img->readImage($image);

    $draw = new ImagickDraw();

    //$draw->setFont("");

    $draw->setFontSize(28);

    $draw->setFillOpacity(0.5);

    $draw->setGravity(Imagick::GRAVITY_SOUTH);

    $img->annotateImage($draw, 0, 0, 0, $watermark_text);
       
   if ($img->writeImage($filename) != true) {
      $img->destroy();
      return false;
   }
   
   $img->destroy();
   
   return true;
}

function tp_im_cmdline_watermark($filename) {
   
   $watermark_text = get_plugin_setting('watermark_text', 'tidypics');
   if (!$watermark_text)
      return;
   
   // plugins can do their own watermark and return false to prevent this function from running
   if (trigger_plugin_hook('tp_watermark', 'imagemagick', $filename, true) === false)
      return;
   
   $im_path = get_plugin_setting('im_path', 'tidypics');
   if (!$im_path) {
      $im_path = "/usr/bin/";
   }
   
   // make sure end of path is /
   if (substr($im_path, strlen($im_path)-1, 1) != "/") $im_path .= "/";

   
   $owner = get_loggedin_user();

   $watermark_text = tp_process_watermark_text($watermark_text, $owner);
   
   $ext = ".png";
   
   $user_stamp_base = tp_get_watermark_filename($watermark_text, $owner);
   
   
   if ( !file_exists( $user_stamp_base . $ext )) { //create the watermark if it doesn't exist
      $commands = array();
      $commands[] = $im_path . 'convert -size 300x50 xc:grey30 -pointsize 20 -gravity center -draw "fill grey70  text 0,0  \''. $watermark_text . '\'" "'. $user_stamp_base . '_fgnd' . $ext . '"';
      $commands[] = $im_path . 'convert -size 300x50 xc:black -pointsize 20 -gravity center -draw "fill white  text  1,1  \''. $watermark_text . '\' text  0,0  \''. $watermark_text . '\' fill black  text -1,-1 \''. $watermark_text . '\'" +matte ' . $user_stamp_base . '_mask' . $ext;
      $commands[] = $im_path . 'composite -compose CopyOpacity  "' . $user_stamp_base . "_mask" . $ext . '" "' . $user_stamp_base . '_fgnd' . $ext . '" "' . $user_stamp_base . $ext . '"';
      $commands[] = $im_path . 'mogrify -trim +repage "' . $user_stamp_base . $ext . '"';
      $commands[] = 'rm "' . $user_stamp_base . '_mask' . $ext . '"';
      $commands[] = 'rm "' . $user_stamp_base . '_fgnd' . $ext . '"';
      
      foreach( $commands as $command ) {
         exec( $command );
      }
   }
   
   //apply the watermark
   $commands = array();
   $commands[] = $im_path . 'composite -gravity south -geometry +0+10 "' . $user_stamp_base . $ext . '" "' . $filename . '" "' . $filename . '_watermarked"';
   $commands[] = "mv \"$filename" . "_watermarked\" \"$filename\"";
   foreach( $commands as $command ) {
      exec( $command );
   }
}
?>
Gitesh
The link to original plugin on elgg comunity site is this.. http://community.elgg.org/pg/plugins/project/385077/developer/tidypics/tidypics-photo-gallery-plugin

if it helps.,

Thanks a lot in advance.
jmraker
You will need to use a graphics library to edit the image which the 1st code block uses. It uses the gd library, then the imagemagick library and the imagemagick command line.

You'd open the image, get the width & height, draw a filled box with the proper opacity and then draw the text and output the file. If the text is always the same you could probably save the background + text in a png file that's wide enough to handle the widest expected image, then all the program has to do is figure out where to place the image so the text is always in the same spot.

Imagemagick
http://valokuva.org/?p=10
http://www.imagemagick.org/discourse-server/viewtopic.php?t=6870
http://php.net/manual/en/book.imagick.php

GD library
http://www.sitepoint.com/watermark-images-php/
http://php.net/manual/en/book.image.php
Gitesh
jmraker wrote:
You will need to use a graphics library to edit the image which the 1st code block uses. It uses the gd library, then the imagemagick library and the imagemagick command line.

You'd open the image, get the width & height, draw a filled box with the proper opacity and then draw the text and output the file. If the text is always the same you could probably save the background + text in a png file that's wide enough to handle the widest expected image, then all the program has to do is figure out where to place the image so the text is always in the same spot.

Imagemagick
http://valokuva.org/?p=10
http://www.imagemagick.org/discourse-server/viewtopic.php?t=6870
http://php.net/manual/en/book.imagick.php

GD library
http://www.sitepoint.com/watermark-images-php/
http://php.net/manual/en/book.image.php


Thanks for this info., wax finally able to get the watermark thing working on my website, this links were pretty useful.,never got the answer on elgg though., the elgg community is dying, sad thing.
Related topics
can i help?
help,Bonding
HELP!!
Help me with MySQL Account Maintenance and phpBB 2.0.15 :((
help, change pass my acc in cpanel
help me upgrade php to 5.
Need help adding a domain
help add admin in phpbb forum
How to solve this problem? Thanks
Help!
Help me change port for phptriad
problam Plz help
Help!!
Google Ads help fund Spyware ?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.