Created
August 28, 2014 05:05
-
-
Save dnikonov/a67c2fe174f2e51baf7b to your computer and use it in GitHub Desktop.
BITRIX: watermark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// Добавление водяного знака на множественное свойство | |
AddEventHandler("iblock", "OnBeforeIBlockElementAdd", array("SrWatermark", "OnBeforeIBlockElementAdd")); | |
AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", array("SrWatermark", "OnBeforeIBlockElementUpdate")); | |
class SrWatermark | |
{ | |
function OnBeforeIBlockElementAdd (&$arFields) | |
{ | |
if (!empty($arFields["PROPERTY_VALUES"][2])) | |
{ | |
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); | |
$wm = imagecreatefrompng($_SERVER['DOCUMENT_ROOT']."/logo.png"); | |
foreach ($arFields["PROPERTY_VALUES"][2] as $key => $value) { | |
if ($key != 'nnew' && !empty($value["VALUE"]["tmp_name"])) { | |
$img = imagecreatefromjpeg($value["VALUE"]["tmp_name"]); | |
imagecopy($img, $wm, imagesx($img) - imagesx($wm), imagesy($img) - imagesy($wm), 0, 0, imagesx($wm), imagesy($wm)); | |
$result = tempnam($tmp_dir, "wmk").".jpg"; | |
$rez = imagejpeg($img, $result, 100); | |
imagedestroy($img); | |
if ($rez) $arFields["PROPERTY_VALUES"][2][$key]["VALUE"]["tmp_name"] = $result; | |
} | |
} | |
imagedestroy($wm); | |
} | |
} | |
function OnBeforeIBlockElementUpdate (&$arFields) | |
{ | |
if (!empty($arFields["PROPERTY_VALUES"][2])) | |
{ | |
$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir(); | |
$wm = imagecreatefrompng($_SERVER['DOCUMENT_ROOT']."/logo.png"); | |
foreach ($arFields["PROPERTY_VALUES"][2] as $key => $value) { | |
if ($key != 'nnew' && !empty($value["VALUE"]["tmp_name"])) { | |
$img = imagecreatefromjpeg($value["VALUE"]["tmp_name"]); | |
imagecopy($img, $wm, imagesx($img) - imagesx($wm), imagesy($img) - imagesy($wm), 0, 0, imagesx($wm), imagesy($wm)); | |
$result = tempnam($tmp_dir, "wmk").".jpg"; | |
$rez = imagejpeg($img, $result, 100); | |
imagedestroy($img); | |
if ($rez) $arFields["PROPERTY_VALUES"][2][$key]["VALUE"]["tmp_name"] = $result; | |
} | |
} | |
imagedestroy($wm); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment