When you use the Lightbox function within ISC, you run the risk (depending on subject) of giving away more than just an idea of what is being sold. You could be giving away the very product itself, one way or another if it happens to be a personal painting or photo from a gallery.
Okay, downgrade the image so any enlargement renders it useless. But fractal based enlargers are getting good at ‘fixing’ this.
So we need an alternative that ‘marks’ the image in a way that renders almost copyright with considerable effort of anybody wanting to use your work.
I have yet to link this into ISC, but it works and is able to produce what we are looking for. But I’m sure somebody will figure that out !??
The class in the background -
Code: Select all
<?
class iMark{
function create_iMark( $main_img_obj, $iMark_img_obj, $alpha_level = 100 ) {
$alpha_level /= 100;
$main_img_obj_w = imagesx( $main_img_obj );
$main_img_obj_h = imagesy( $main_img_obj );
$iMark_img_obj_w = imagesx( $iMark_img_obj );
$iMark_img_obj_h = imagesy( $iMark_img_obj );
$main_img_obj_min_x = floor( ( $main_img_obj_w / 2 ) - ( $iMark_img_obj_w / 2 ) );
$main_img_obj_max_x = ceil( ( $main_img_obj_w / 2 ) + ( $iMark_img_obj_w / 2 ) );
$main_img_obj_min_y = floor( ( $main_img_obj_h / 2 ) - ( $iMark_img_obj_h / 2 ) );
$main_img_obj_max_y = ceil( ( $main_img_obj_h / 2 ) + ( $iMark_img_obj_h / 2 ) );
$return_img = imagecreatetruecolor( $main_img_obj_w, $main_img_obj_h );
for( $y = 0; $y < $main_img_obj_h; $y++ ) {
for( $x = 0; $x < $main_img_obj_w; $x++ ) {
$return_color = NULL;
$iMark_x = $x - $main_img_obj_min_x;
$iMark_y = $y - $main_img_obj_min_y;
$main_rgb = imagecolorsforindex( $main_img_obj, imagecolorat( $main_img_obj, $x, $y ) );
if ($iMark_x >= 0 && $iMark_x < $iMark_img_obj_w &&
$iMark_y >= 0 && $iMark_y < $iMark_img_obj_h ) {
$iMark_rbg = imagecolorsforindex( $iMark_img_obj, imagecolorat( $iMark_img_obj, $iMark_x, $iMark_y ));
$iMark_alpha = round( ( ( 127 - $iMark_rbg['alpha'] ) / 127 ), 2 );
$iMark_alpha = $iMark_alpha * $alpha_level;
$avg_red = $this->_get_ave_color( $main_rgb['red'], $iMark_rbg['red'], $iMark_alpha );
$avg_green = $this->_get_ave_color( $main_rgb['green'], $iMark_rbg['green'], $iMark_alpha );
$avg_blue = $this->_get_ave_color( $main_rgb['blue'], $iMark_rbg['blue'], $iMark_alpha );
$return_color = $this->_get_image_color( $return_img, $avg_red, $avg_green, $avg_blue );
} else {
$return_color = imagecolorat( $main_img_obj, $x, $y );
}
imagesetpixel( $return_img, $x, $y, $return_color );
}
}
return $return_img;
}
function _get_ave_color( $color_a, $color_b, $alpha_level ) {
return round( ( ( $color_a * ( 1 - $alpha_level ) ) + ( $color_b * $alpha_level ) ) );
}
function _get_image_color($im, $r, $g, $b) {
$c=imagecolorexact($im, $r, $g, $b);
if ($c!=-1) return $c;
$c=imagecolorallocate($im, $r, $g, $b);
if ($c!=-1) return $c;
return imagecolorclosest($im, $r, $g, $b);
}
}
?>
The line ==
function create_iMark( $main_img_obj, $iMark_img_obj, $alpha_level = 100 ) is default to 100. If you want the watermark to seem to be more softer or bearly seen, lower this value.
The 'calling' script usingthe Class -
Code: Select all
<?
$___notjson=1;
include 'imark.php';
$iMark = new iMark();
$main_img_obj = imagecreatefromjpeg($_GET['main']);
$iMark_img_obj = imagecreatefrompng($_GET['iMark']);
$return_img_obj = $iMark->create_iMark($main_img_obj, $iMark_img_obj, 66);
header('Content-Type: image/jpeg');
header('Content-Disposition: inline; filename=' . $_GET['src']);
imagejpeg($return_img_obj, '', 50);
?>
And the line you would use to run the watermark script -
<img src="image.php?main=product.jpg&iMark=logo.png">
Where product.jpg is the image to be protected and logo.png is what will mark the image. (the PNG used was set at 8bit RGB mode before being saved from photoshop)
To embed this in to ISC (my next to do) -
ISC’s Lightbox option to display product, uses the lines located in includes/display/ProductDetails.php
while($image = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
$GLOBALS['LightBoxImageList'] .= '<a ';
$GLOBALS['LightBoxImageList'] .= 'href="'.$GLOBALS['ShopPath'].'/'.GetConfig('ImageDirectory').'/'.$image['imagefile'].'" ';
$GLOBALS['LightBoxImageList'] .= 'title="'.isc_html_escape($GLOBALS['ISC_CLASS_PRODUCT']->GetProductName()).'"';
$GLOBALS['LightBoxImageList'] .= '> </a>';
We need to ‘add’ into this line –
$GLOBALS['LightBoxImageList'] .= 'href="'.$GLOBALS['ShopPath'].'/'.GetConfig('ImageDirectory').'/'.$image['imagefile'].'" ';
Making the line before correcting syntax –
http://www.xxxxxxx.com/image.php?main= '.$GLOBALS['ShopPath'].'/'.GetConfig('ImageDirectory').'/'.$image['imagefile'].'
&iMark=logo.png
To view this line another way -
http://www.xxxxxxx.com/image.php?main=product.jpg
&iMark=logo.png
Where the section -
'.$GLOBALS['ShopPath'].'/'.GetConfig('ImageDirectory').'/'.$image['imagefile'].' represents the 'product.jpg' or image shown through Lightbox.