AVE.CMS v3.28
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

224 lines
5.0 KiB

7 years ago
<?php
7 years ago
/**
* AVE.cms
*
* @package AVE.cms
* @version 3.x
* @filesource
* @copyright © 2007-2014 AVE.cms, http://www.ave-cms.ru
*
* @license GPL v.2
*/
/**
* Функция дописывает в JPG файлы IPTC Tag
*
* @param string $rec
* @param string $data
* @param string $value
* @return string
*/
if (! function_exists('iptc_make_tag'))
7 years ago
{
7 years ago
function iptc_make_tag($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
7 years ago
7 years ago
if ($length < 0x8000)
{
$retval .= chr($length >> 8) . chr($length & 0xFF);
}
else
{
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
}
7 years ago
7 years ago
return $retval . $value;
}
}
7 years ago
7 years ago
/**
* Функция накладывает watermark на заданный файл
*
* @param string $file URL Файла
* @param string $position Позиция
* @param int $transparency Прозарчность
* @return string link
*/
6 years ago
function watermarks ($file, $position='center', $transparency=100)
7 years ago
{
if (! defined('WATERMARKS_DIR') || ! defined('WATERMARKS_FILE'))
return $file;
7 years ago
7 years ago
$save = true;
7 years ago
7 years ago
$margin = 10;
7 years ago
7 years ago
$file_info = pathinfo($file);
7 years ago
7 years ago
$watermarkFile = BASE_DIR . '/' . WATERMARKS_FILE;
$watermarkDir = BASE_DIR . '/' . WATERMARKS_DIR;
7 years ago
7 years ago
$imagePath = BASE_DIR . '/' . trim($file_info['dirname'], '/');
$imageName = $file_info['basename'];
7 years ago
7 years ago
$copyPath = $watermarkDir . '/' . trim($file_info['dirname'], '/');
$copyName = $imageName;
7 years ago
6 years ago
if (file_exists($watermarkDir . $file))
7 years ago
return $file;
7 years ago
7 years ago
if (! is_dir($watermarkDir))
{
@mkdir($watermarkDir, 0777, true);
write_htaccess_deny($watermarkDir);
}
7 years ago
7 years ago
if (file_exists("$copyPath/$copyName") || !file_exists("$imagePath/$imageName"))
7 years ago
$save = false;
7 years ago
if (file_exists($watermarkFile) && file_exists("$imagePath/$imageName"))
{
$size_image = getimagesize("$imagePath/$imageName");
$size_wtmrk = getimagesize($watermarkFile);
7 years ago
7 years ago
list($xImage, $yImage) = $size_image;
list($xWtmrk, $yWtmrk) = $size_wtmrk;
7 years ago
7 years ago
if ($xImage < $xWtmrk || $yImage < $yWtmrk)
$save = false;
else
$save = true;
7 years ago
}
7 years ago
if (file_exists("$copyPath/$copyName"))
$save = false;
if ($save)
7 years ago
{
7 years ago
if (! is_dir($copyPath) && !@mkdir($copyPath, 0777, true))
return $file;
7 years ago
7 years ago
require_once BASE_DIR.'/class/class.thumbnail.php';
7 years ago
7 years ago
$watermark = new Image_Toolbox("$imagePath/$imageName");
if (rename("$imagePath/$imageName", "$copyPath/$copyName"))
7 years ago
{
7 years ago
$old = umask(0);
chmod("$copyPath/$copyName", 0777);
umask($old);
}
7 years ago
7 years ago
switch ($position)
{
case 'top':
case 'topcenter':
$xLogoPosition = 'center -';
$yLogoPosition = 'top +'.$margin;
break;
case 'topleft':
$xLogoPosition = 'left +'.$margin;
$yLogoPosition = 'top +'.$margin;
break;
case 'topright':
$xLogoPosition = 'right -'.$margin;
$yLogoPosition = 'top +'.$margin;
break;
case 'center':
$xLogoPosition = 'center -';
$yLogoPosition = 'center -';
break;
case 'centerleft':
$xLogoPosition = 'left +'.$margin;
$yLogoPosition = 'center -';
break;
case 'centerright':
$xLogoPosition = 'right -'.$margin;
$yLogoPosition = 'center -';
break;
case 'bottom':
case 'bottomcenter':
$xLogoPosition = 'center -';
$yLogoPosition = 'bottom -'.$margin;
break;
case 'bottomleft':
$xLogoPosition = 'left +'.$margin;
$yLogoPosition = 'bottom -'.$margin;
break;
case 'bottomright':
$xLogoPosition = 'right -'.$margin;
$yLogoPosition = 'bottom -'.$margin;
break;
case 'repeat':
$xLogoPosition = 'repeat ';
$yLogoPosition = 'repeat ';
break;
default:
$xLogoPosition = 'center -';
$yLogoPosition = 'center -';
break;
}
7 years ago
7 years ago
$watermark->addImage($watermarkFile);
$watermark->blend($xLogoPosition, $yLogoPosition, IMAGE_TOOLBOX_BLEND_COPY, $transparency);
$watermark->save("$imagePath/$imageName");
7 years ago
7 years ago
if ($watermark->_img['main']['type'] == 2)
{
6 years ago
// $image = getimagesize("$imagePath/$imageName", $info); Not used
7 years ago
7 years ago
if (! isset($info['APP13']))
7 years ago
{
7 years ago
$sitename = get_settings('site_name');
// установка IPTC тэгов
$iptc = array(
'2#120' => iconv("UTF-8","WINDOWS-1251",$sitename),
'2#116' => "http://".$_SERVER['SERVER_NAME']
);
// Преобразование IPTC тэгов в двоичный код
$data = '';
foreach ($iptc AS $tag => $string)
{
$tag = substr($tag, 2);
$data .= iptc_make_tag(2, $tag, $string);
}
// Встраивание IPTC данных
$content = iptcembed($data, "$imagePath/$imageName");
// запись нового изображения в файл
$fp = fopen("$imagePath/$imageName", "wb");
fwrite($fp, $content);
fclose($fp);
7 years ago
}
}
7 years ago
unset($watermark);
7 years ago
}
7 years ago
return $file;
7 years ago
}
7 years ago
?>