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

8 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'))
8 years ago
{
7 years ago
function iptc_make_tag($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
8 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);
}
8 years ago
7 years ago
return $retval . $value;
}
}
8 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;
8 years ago
7 years ago
$save = true;
8 years ago
7 years ago
$margin = 10;
8 years ago
7 years ago
$file_info = pathinfo($file);
8 years ago
7 years ago
$watermarkFile = BASE_DIR . '/' . WATERMARKS_FILE;
$watermarkDir = BASE_DIR . '/' . WATERMARKS_DIR;
8 years ago
7 years ago
$imagePath = BASE_DIR . '/' . trim($file_info['dirname'], '/');
$imageName = $file_info['basename'];
8 years ago
7 years ago
$copyPath = $watermarkDir . '/' . trim($file_info['dirname'], '/');
$copyName = $imageName;
8 years ago
6 years ago
if (file_exists($watermarkDir . $file))
7 years ago
return $file;
8 years ago
7 years ago
if (! is_dir($watermarkDir))
{
@mkdir($watermarkDir, 0777, true);
write_htaccess_deny($watermarkDir);
}
8 years ago
7 years ago
if (file_exists("$copyPath/$copyName") || !file_exists("$imagePath/$imageName"))
8 years ago
$save = false;
7 years ago
if (file_exists($watermarkFile) && file_exists("$imagePath/$imageName"))
{
$size_image = getimagesize("$imagePath/$imageName");
$size_wtmrk = getimagesize($watermarkFile);
8 years ago
7 years ago
list($xImage, $yImage) = $size_image;
list($xWtmrk, $yWtmrk) = $size_wtmrk;
8 years ago
7 years ago
if ($xImage < $xWtmrk || $yImage < $yWtmrk)
$save = false;
else
$save = true;
8 years ago
}
7 years ago
if (file_exists("$copyPath/$copyName"))
$save = false;
if ($save)
8 years ago
{
7 years ago
if (! is_dir($copyPath) && !@mkdir($copyPath, 0777, true))
return $file;
8 years ago
7 years ago
require_once BASE_DIR.'/class/class.thumbnail.php';
8 years ago
7 years ago
$watermark = new Image_Toolbox("$imagePath/$imageName");
if (rename("$imagePath/$imageName", "$copyPath/$copyName"))
8 years ago
{
7 years ago
$old = umask(0);
chmod("$copyPath/$copyName", 0777);
umask($old);
}
8 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;
}
8 years ago
7 years ago
$watermark->addImage($watermarkFile);
$watermark->blend($xLogoPosition, $yLogoPosition, IMAGE_TOOLBOX_BLEND_COPY, $transparency);
$watermark->save("$imagePath/$imageName");
8 years ago
7 years ago
if ($watermark->_img['main']['type'] == 2)
{
6 years ago
// $image = getimagesize("$imagePath/$imageName", $info); Not used
8 years ago
7 years ago
if (! isset($info['APP13']))
8 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);
8 years ago
}
}
7 years ago
unset($watermark);
8 years ago
}
7 years ago
return $file;
8 years ago
}
7 years ago
?>