Joomla 1.0.xx mambot to insert watermarked image...help?
Posted: Sat Feb 09, 2008 12:34 am
I'm trying to code a mambot for my Joomla! 1.0.13 install that will display a watermarked image for guests and a non-watermarkedd image for registered users. This is my code:
The images are organized in folders outside my www folder so they can not be directly accessed via the web. They are not watermarked normally and should only be watermarked on the fly when viewed by a guest. My code is adapted from code originally used in a Smarty template, and the watermarking code worked. I had hoped only a few modifications would make it work as a mambot. My intention was to use the mambot like this:
However, as is, it displays a broken image placeholder and nothing more. Any ideas?
Code: Select all
function botSecureWM( $published, &$row, &$params, $page=0 ) {
// simple performance check to determine whether bot should process further
if ( strpos( $row->text, 'securewm' ) === false ) {
return true;
}
// define the regular expression for the bot
$regex = "#{securewm}(.*?){/securewm}#s";
// $regex = '/{(securewm)\s*(.*?)}/i';
// check whether mosimage has been disabled for page
// check whether mambot has been unpublished
if (!$published || !$params->get( 'image' )) {
$row->text = preg_replace( $regex, '', $row->text );
return;
}
$row->text = preg_replace_callback( $regex, 'botSecureWM_replacer', $row->text );
return true;
}
function botSecureWM_replacer( &$matches ) {
global $my;
//Check for the usertype
if (!isset($my->usertype) or $my->usertype=="")
{
//Guests see a watermarked image
header('content-type: image/jpeg');
$src='/homepages/7/d116823254/htdocs/mwpics/'.$matches[0];
$watermark = imagecreatefrompng('MW_WaterMark.png');
$dest_x = 15;
$dest_y = 80;
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatefromjpeg($src);
$size = getimagesize($src);
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
} else {
//Members see the non-watermarked image
header('content-type: image/jpeg');
$src='/homepages/7/d116823254/htdocs/mwpics/'.$matches[0];
$image = imagecreatefromjpeg($src);
$size = getimagesize($src);
imagejpeg($image);
imagedestroy($image);
}
return "";
}
The images are organized in folders outside my www folder so they can not be directly accessed via the web. They are not watermarked normally and should only be watermarked on the fly when viewed by a guest. My code is adapted from code originally used in a Smarty template, and the watermarking code worked. I had hoped only a few modifications would make it work as a mambot. My intention was to use the mambot like this:
Code: Select all
<img src="{securewm}/path/to/image.jpg{/securewm}" />
However, as is, it displays a broken image placeholder and nothing more. Any ideas?