<?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>Thu, 09 Sep 2010 04:48:01 +0000</pubDate>

<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>
