<?xml version="1.0" encoding="UTF-8"?><!-- generator="bbPress" -->

<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
>

<channel>
<title>PHP Thumb Topic: Plugin: Watermarking Issue</title>
<link>http://phpthumb.gxdlabs.com/forums/</link>
<description>Help, Suggestions, and General Discussion</description>
<language>en</language>
<pubDate>Tue, 07 Feb 2012 12:03:47 +0000</pubDate>

<item>
<title>ecarlevaro on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-174</link>
<pubDate>Tue, 08 Mar 2011 07:11:17 +0000</pubDate>
<dc:creator>ecarlevaro</dc:creator>
<guid isPermaLink="false">174@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Hi! I`m having troubles with memory limit when i use the watermark plugin with 60 images of 700x600 pixeles at 150 KB each image (and the watermark is only a PNG image of 1.32 KB).&#60;/p&#62;
&#60;p&#62;In fact, with 60 images, memory_get_usage() say is in use 67 MB of memory!!!.&#60;/p&#62;
&#60;p&#62;I'm not sure it is possible optimize the watermark plugin code.&#60;/p&#62;
&#60;p&#62;The code i'm using is similar:&#60;/p&#62;
&#60;pre&#62;&#60;code&#62;&#38;lt;?php
class GdWatermarkLib
{
 /**
 * Instance of GdThumb passed to this class
 *
 * @var GdThumb
 */
 protected $parentInstance;
 protected $currentDimensions;
 protected $workingImage;
 protected $newImage;
 protected $options;

 public function createWatermark ($watermark, $mask_position, $mask_padding, $that)
 {
 // bring stuff from the parent class into this class...
 $this-&#38;gt;parentInstance = $that;
 $this-&#38;gt;currentDimensions = $this-&#38;gt;parentInstance-&#38;gt;getCurrentDimensions();
 $this-&#38;gt;mask_position = $mask_position;

 $width = $this-&#38;gt;currentDimensions[&#38;#39;width&#38;#39;];
 $height = $this-&#38;gt;currentDimensions[&#38;#39;height&#38;#39;];

 $watermarksize = getimagesize($watermark);
 $dest_x = $width - $watermarksize[0] - 55;
 $dest_y = $height - $watermarksize[1] - 55;
 //$watermark = imagecreatefrompng($watermark);

 $pathinfo = pathinfo($watermark);
 $var1 = $pathinfo[&#38;#39;extension&#38;#39;];
 $var2 = &#38;quot;png&#38;quot;;
 $var3 = &#38;quot;jpeg&#38;quot;;
 $var4 = &#38;quot;jpg&#38;quot;;
 $var5 = &#38;quot;gif&#38;quot;;
 if(strcasecmp($var1, $var2) == 0){
 $watermark = @imagecreatefrompng($watermark);
 }elseif((strcasecmp($var1, $var3) == 0) &#124;&#124; (strcasecmp($var1, $var4) == 0)){
 $watermark = @imagecreatefromjpeg($watermark);
 }elseif(strcasecmp($var1, $var5) == 0){
 $watermark = @imagecreatefromgif($watermark);
 }

 switch($mask_position) {
  case &#38;#39;cc&#38;#39;:
  // Center
  $dest_x = round(($width - $watermarksize[0]) / 2);
  $dest_y = round(($height - $watermarksize[1]) / 2);
  break;
  case &#38;#39;lt&#38;#39;:
  // Left Top
  $dest_x = $mask_padding;
  $dest_y = $mask_padding;
  break;
  case &#38;#39;rt&#38;#39;:
  // Right Top
  $dest_x = $width - $mask_padding - $watermarksize[0];
  $dest_y = $mask_padding;
  break;
  case &#38;#39;lb&#38;#39;:
  // Left Bottom
  $dest_x = $mask_padding;
  $dest_y = $height - $mask_padding - $watermarksize[1];
  break;
  case &#38;#39;rb&#38;#39;:
  // Right Bottom
  $dest_x = $width - $mask_padding - $watermarksize[0];
  $dest_y = $height - $mask_padding - $watermarksize[1];
  break;
  case &#38;#39;cb&#38;#39;:
  // Center Bottom
  $dest_x = round(($width - $watermarksize[0]) / 2);
  $dest_y = $height - $mask_padding - $watermarksize[1];
  break;
  }

 imagecopy($this-&#38;gt;parentInstance-&#38;gt;getOldImage(), $watermark, $dest_x, $dest_y, 0, 0, $watermarksize[0], $watermarksize[1]);

 return $that;
 }
}

$pt = PhpThumb::getInstance();
$pt-&#38;gt;registerPlugin(&#38;#39;GdWatermarkLib&#38;#39;,&#38;#39;gd&#38;#39;);

?&#38;gt;&#60;/code&#62;&#60;/pre&#62;
&#60;p&#62;If there is possible optimize something in this code, i will be grateful.&#60;/p&#62;
&#60;p&#62;I just need write text on the image, so i'm using watermark plugin but if there is another GD function to write text over the image it will be useful to me
&#60;/p&#62;</description>
</item>
<item>
<title>stormy0711 on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-94</link>
<pubDate>Thu, 27 Aug 2009 12:14:47 +0000</pubDate>
<dc:creator>stormy0711</dc:creator>
<guid isPermaLink="false">94@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Use &#60;/p&#62;
&#60;p&#62;&#60;code&#62;class GdWatermarkLib&#60;br /&#62;
{&#60;br /&#62;
/**&#60;br /&#62;
* Instance of GdThumb passed to this class&#60;br /&#62;
*&#60;br /&#62;
* @var GdThumb&#60;br /&#62;
*/&#60;br /&#62;
protected $parentInstance;&#60;br /&#62;
protected $currentDimensions;&#60;br /&#62;
protected $workingImage;&#60;br /&#62;
protected $newImage;&#60;br /&#62;
protected $options;&#60;/p&#62;
&#60;p&#62;public function createWatermark ($watermark, $that)&#60;br /&#62;
{&#60;br /&#62;
// bring stuff from the parent class into this class...&#60;br /&#62;
$this-&#38;gt;parentInstance = $that;&#60;br /&#62;
$this-&#38;gt;currentDimensions = $this-&#38;gt;parentInstance-&#38;gt;getCurrentDimensions();&#60;/p&#62;
&#60;p&#62;$width = $this-&#38;gt;currentDimensions['width'];&#60;br /&#62;
$height = $this-&#38;gt;currentDimensions['height'];&#60;/p&#62;
&#60;p&#62;$watermarksize = getimagesize($watermark);&#60;br /&#62;
$dest_x = $width - $watermarksize[0] - 5;&#60;br /&#62;
$dest_y = $height - $watermarksize[1] - 5;&#60;br /&#62;
//$watermark = imagecreatefrompng($watermark);&#60;/p&#62;
&#60;p&#62;$pathinfo = pathinfo($watermark);&#60;br /&#62;
  $var1 = $pathinfo['extension'];&#60;br /&#62;
  $var2 = &#34;png&#34;;&#60;br /&#62;
  $var3 = &#34;jpeg&#34;;&#60;br /&#62;
  $var4 = &#34;jpg&#34;;&#60;br /&#62;
  $var5 = &#34;gif&#34;;&#60;br /&#62;
  if(strcasecmp($var1, $var2) == 0){&#60;br /&#62;
  $watermark = @imagecreatefrompng($watermark);&#60;br /&#62;
  }elseif((strcasecmp($var1, $var3) == 0) &#124;&#124; (strcasecmp($var1, $var4) == 0)){&#60;br /&#62;
  $watermark = @imagecreatefromjpeg($watermark);&#60;br /&#62;
  }elseif(strcasecmp($var1, $var5) == 0){&#60;br /&#62;
  $watermark = @imagecreatefromgif($watermark);&#60;br /&#62;
  }&#60;/p&#62;
&#60;p&#62;imagecopy($this-&#38;gt;parentInstance-&#38;gt;getOldImage(), $watermark, $dest_x, $dest_y, 0, 0, $watermarksize[0], $watermarksize[1]);&#60;/p&#62;
&#60;p&#62;return $that;&#60;br /&#62;
}&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;$pt = PhpThumb::getInstance();&#60;br /&#62;
$pt-&#38;gt;registerPlugin('GdWatermarkLib','gd');&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;for all image-Types
&#60;/p&#62;</description>
</item>
<item>
<title>menic on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-36</link>
<pubDate>Sun, 28 Jun 2009 03:29:47 +0000</pubDate>
<dc:creator>menic</dc:creator>
<guid isPermaLink="false">36@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Could you extend it with alpha blending png support?&#60;br /&#62;
Thanx in advance :)
&#60;/p&#62;</description>
</item>
<item>
<title>Ian on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-6</link>
<pubDate>Sat, 13 Jun 2009 19:32:16 +0000</pubDate>
<dc:creator>Ian</dc:creator>
<guid isPermaLink="false">6@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Any time :)
&#60;/p&#62;</description>
</item>
<item>
<title>shockerusa on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-5</link>
<pubDate>Fri, 12 Jun 2009 06:04:57 +0000</pubDate>
<dc:creator>shockerusa</dc:creator>
<guid isPermaLink="false">5@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;It works! Thank you!
&#60;/p&#62;</description>
</item>
<item>
<title>Ian on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-4</link>
<pubDate>Thu, 11 Jun 2009 21:52:00 +0000</pubDate>
<dc:creator>Ian</dc:creator>
<guid isPermaLink="false">4@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Justin, got a fix for you... here's the code I got working:&#60;br /&#62;
&#60;code&#62;&#38;lt;?php&#60;br /&#62;
class GdWatermarkLib&#60;br /&#62;
{&#60;br /&#62;
	/**&#60;br /&#62;
	 * Instance of GdThumb passed to this class&#60;br /&#62;
	 *&#60;br /&#62;
	 * @var GdThumb&#60;br /&#62;
	 */&#60;br /&#62;
	protected $parentInstance;&#60;br /&#62;
	protected $currentDimensions;&#60;br /&#62;
	protected $workingImage;&#60;br /&#62;
	protected $newImage;&#60;br /&#62;
	protected $options;&#60;/p&#62;
&#60;p&#62;	public function createWatermark ($watermark, &#38;#38;$that)&#60;br /&#62;
	{&#60;br /&#62;
		// bring stuff from the parent class into this class...&#60;br /&#62;
		$this-&#38;gt;parentInstance 		= $that;&#60;br /&#62;
		$this-&#38;gt;currentDimensions 	= $this-&#38;gt;parentInstance-&#38;gt;getCurrentDimensions();&#60;/p&#62;
&#60;p&#62;		$width 	= $this-&#38;gt;currentDimensions['width'];&#60;br /&#62;
		$height = $this-&#38;gt;currentDimensions['height'];&#60;/p&#62;
&#60;p&#62;		$watermarksize 	= getimagesize($watermark);&#60;br /&#62;
		$dest_x 		= $width - $watermarksize[0] - 5;&#60;br /&#62;
		$dest_y 		= $height - $watermarksize[1] - 5;&#60;br /&#62;
		$watermark 		= imagecreatefromjpeg($watermark);&#60;/p&#62;
&#60;p&#62;		imagecopymerge($this-&#38;gt;parentInstance-&#38;gt;getOldImage(), $watermark, $dest_x, $dest_y, 0, 0, $watermarksize[0], $watermarksize[1], 100);&#60;/p&#62;
&#60;p&#62;		return $that;&#60;br /&#62;
	}&#60;br /&#62;
}&#60;/p&#62;
&#60;p&#62;$pt = PhpThumb::getInstance();&#60;br /&#62;
$pt-&#38;gt;registerPlugin('GdWatermarkLib','gd');&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;And I tested it with:&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
$thumb = PhpThumbFactory::create('test.jpg');&#60;br /&#62;
$thumb-&#38;gt;createWatermark('watermark.jpg')-&#38;gt;show();&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;And just for fun (to make sure everything works together):&#60;br /&#62;
&#60;code&#62;&#60;br /&#62;
$thumb = PhpThumbFactory::create('test.jpg');&#60;br /&#62;
$thumb-&#38;gt;createWatermark('watermark.jpg')-&#38;gt;createReflection(40, 40, 80, true, '#a4a4a4')-&#38;gt;show();&#60;br /&#62;
&#60;/code&#62;
&#60;/p&#62;</description>
</item>
<item>
<title>Ian on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-3</link>
<pubDate>Thu, 11 Jun 2009 21:37:24 +0000</pubDate>
<dc:creator>Ian</dc:creator>
<guid isPermaLink="false">3@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;I'll take a look into it and get back to you :)
&#60;/p&#62;</description>
</item>
<item>
<title>shockerusa on "Plugin: Watermarking Issue"</title>
<link>http://phpthumb.gxdlabs.com/forums/topic/plugin-watermarking-issue#post-2</link>
<pubDate>Thu, 11 Jun 2009 16:53:50 +0000</pubDate>
<dc:creator>shockerusa</dc:creator>
<guid isPermaLink="false">2@http://phpthumb.gxdlabs.com/forums/</guid>
<description>&#60;p&#62;Hello,&#60;/p&#62;
&#60;p&#62;I'm trying to create an plugin to watermark images, however i'm running into a problem.&#60;/p&#62;
&#60;p&#62;My goal is to keep the orginal size images and just watermark them, while also creating thumbnails of them.&#60;br /&#62;
The problem is when I'm trying to watermark them and save them, php throws an warning.&#60;/p&#62;
&#60;p&#62;Here is my code for the plugin:&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
class GdWatermarkLib&#60;br /&#62;
{&#60;br /&#62;
	/**&#60;br /&#62;
	 * Instance of GdThumb passed to this class&#60;br /&#62;
	 *&#60;br /&#62;
	 * @var GdThumb&#60;br /&#62;
	 */&#60;br /&#62;
	protected $parentInstance;&#60;br /&#62;
	protected $currentDimensions;&#60;br /&#62;
	protected $workingImage;&#60;br /&#62;
	protected $newImage;&#60;br /&#62;
	protected $options;&#60;/p&#62;
&#60;p&#62;	public function createWatermark ($watermark, &#38;#38;$that)&#60;br /&#62;
	{&#60;br /&#62;
		// bring stuff from the parent class into this class...&#60;br /&#62;
		$this-&#38;gt;parentInstance 		= $that;&#60;br /&#62;
		$this-&#38;gt;currentDimensions 	= $this-&#38;gt;parentInstance-&#38;gt;getCurrentDimensions();&#60;br /&#62;
		$this-&#38;gt;workingImage			= $this-&#38;gt;parentInstance-&#38;gt;getWorkingImage();&#60;/p&#62;
&#60;p&#62;		$width				= $this-&#38;gt;currentDimensions['width'];&#60;br /&#62;
		$height				= $this-&#38;gt;currentDimensions['height'];&#60;/p&#62;
&#60;p&#62;	$watermarksize = getimagesize($watermark);&#60;br /&#62;
	$dest_x = $width - $watermarksize[0] - 5;&#60;br /&#62;
	$dest_y = $height - $watermarksize[1] - 5; &#60;/p&#62;
&#60;p&#62;		$watermark = imagecreatefromjpeg($watermark);&#60;br /&#62;
		imagecopymerge($this-&#38;gt;workingImage, $watermark, $dest_x, $dest_y, 0, 0, $watermarksize[0], $watermarksize[1], 100);  &#60;/p&#62;
&#60;p&#62;		return $that;&#60;br /&#62;
	}&#60;/p&#62;
&#60;p&#62;}&#60;/p&#62;
&#60;p&#62;$pt = PhpThumb::getInstance();&#60;br /&#62;
$pt-&#38;gt;registerPlugin('GdWatermarkLib', 'gd');&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Here are my lines of code to call it.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
require_once 'functions/ThumbLib.inc.php';&#60;/p&#62;
&#60;p&#62;$thumb = PhpThumbFactory::create('test.jpg');&#60;/p&#62;
&#60;p&#62;$thumb-&#38;gt;createWatermark('watermark.jpg')-&#38;gt;save('watermarked_image.jpg');&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;The code above just takes the image, applies the watermark and saves it.&#60;/p&#62;
&#60;p&#62;When I run the code above I get &#60;blockquote&#62;Warning: imagecopymerge(): supplied argument is not a valid Image resource in C:\AppServ\www\imagetest\thumb_plugins\gd_watermark.inc.php on line 64&#60;/blockquote&#62;&#60;/p&#62;
&#60;p&#62;However, if I try to resize it before applying the watermark, it works fine. See code below.&#60;/p&#62;
&#60;p&#62;&#60;code&#62;&#60;br /&#62;
require_once 'functions/ThumbLib.inc.php';&#60;/p&#62;
&#60;p&#62;$thumb = PhpThumbFactory::create('test.jpg');&#60;/p&#62;
&#60;p&#62;$thumb-&#38;gt;resize(600, 600)-&#38;gt;createWatermark('watermark.jpg')-&#38;gt;save('watermarked_image.jpg');&#60;br /&#62;
&#60;/code&#62;&#60;/p&#62;
&#60;p&#62;Environment:&#60;br /&#62;
Windows XP&#60;br /&#62;
Apache 2&#60;br /&#62;
PHP Version 5.2.1&#60;br /&#62;
GD Version 2.0.28&#60;/p&#62;
&#60;p&#62;Do you have any ideas what might be causing that?&#60;/p&#62;
&#60;p&#62;Thanks,&#60;/p&#62;
&#60;p&#62;Justin&#60;/p&#62;
&#60;p&#62;P.S Awesome script!
&#60;/p&#62;</description>
</item>

</channel>
</rss>

