<?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: Forum: Plugin Development - Recent Topics</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:23 +0000</pubDate>

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

