<?
// Добавление водяной марки
AddEventHandler("iblock", "OnBeforeIBlockElementAdd", array("SrWatermark", "OnBeforeIBlockElementAdd"));
AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", array("SrWatermark", "OnBeforeIBlockElementUpdate"));
class SrWatermark
{
function OnBeforeIBlockElementAdd (&$arFields)
{
header("Content-type: image/png");
$res = imagecreate(158,158);
$img = imagecreatefromjpeg($arFields["DETAIL_PICTURE"]["tmp_name"]);
$logo = imagecreatefrompng($_SERVER["DOCUMENT_ROOT"]."/images/watermark.png");
imagecopyresized ($res,$img,
0,0,
0,0,
158,158,
imagesx($img),imagesy($img));
imagecopy ($res,$logo,60,110,0,0,60,12);
$trans = imagecolorat($res,0,0);
imagecolortransparent($res,$trans);
imagepng($res);
$arFields["DETAIL_PICTURE"]["tmp_name"] = $res;
}
function OnBeforeIBlockElementUpdate (&$arFields)
{
header("Content-type: image/png");
$res = imagecreate(158,158);
$img = imagecreatefromjpeg($arFields["DETAIL_PICTURE"]["tmp_name"]);
$logo = imagecreatefrompng($_SERVER["DOCUMENT_ROOT"]."/images/watermark.png");
imagecopyresized ($res,$img,
0,0,
0,0,
158,158,
imagesx($img),imagesy($img));
imagecopy ($res,$logo,60,110,0,0,60,12);
$trans = imagecolorat($res,0,0);
imagecolortransparent($res,$trans);
imagepng($res);
$arFields["DETAIL_PICTURE"]["tmp_name"] = $res;
}
}
?>
|