Skip to content

Commit

Permalink
Доработка модуля Image
Browse files Browse the repository at this point in the history
  • Loading branch information
mzhelskiy committed Sep 28, 2015
1 parent 19d7f48 commit 54f76be
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions classes/modules/image/entity/Image.entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,17 +300,18 @@ public function cropFromSelected($aSelectedSize, $iCanvasWidth = null)
* Сохраняет изображение в файл
*
* @param string $sFile Полный путь до файла сохранения
* @param array $aParamsSave Дополнительные опции сохранения, например, не делать вотермарк
*
* @return bool | string При успешном сохранении возвращает полный путь до файла
*/
public function save($sFile)
public function save($sFile, $aParamsSave = array())
{
$_this = $this;
return $this->callExceptionMethod(function ($oImage) use ($_this, $sFile) {
return $this->callExceptionMethod(function ($oImage) use ($_this, $sFile, $aParamsSave) {

$sFormat = ($_this->getParam('format_auto') && $_this->getFormat()) ? $_this->getFormat() : $_this->getParam('format');
$sFileTmp = Config::Get('path.tmp.server') . DIRECTORY_SEPARATOR . func_generator(20);
$_this->internalSave($sFileTmp, $sFormat);
$_this->internalSave($sFileTmp, $sFormat, $aParamsSave);

return $_this->Image_SaveFile($sFileTmp, $sFile, 0666, true);

Expand All @@ -333,7 +334,7 @@ public function saveTmp()
}
$sFormat = ($_this->getParam('format_auto') && $_this->getFormat()) ? $_this->getFormat() : $_this->getParam('format');
$sFileTmp = $sDirTmp . DIRECTORY_SEPARATOR . func_generator(20);
$_this->internalSave($sFileTmp, $sFormat);
$_this->internalSave($sFileTmp, $sFormat, array('skip_watermark' => true));
return $sFileTmp;

});
Expand All @@ -344,17 +345,18 @@ public function saveTmp()
*
* @param string $sDir Директория куда нужно сохранить изображение относительно корня сайта (path.root.server)
* @param string $sFile Имя файла для сохранения, без расширения (расширение подставляется автоматически в зависимости от типа изображения)
* @param array $aParamsSave Дополнительные опции сохранения, например, не делать вотермарк
*
* @return bool | string При успешном сохранении возвращает полный путь до файла
*/
public function saveSmart($sDir, $sFile)
public function saveSmart($sDir, $sFile, $aParamsSave = array())
{
$_this = $this;
return $this->callExceptionMethod(function ($oImage) use ($_this, $sDir, $sFile) {
return $this->callExceptionMethod(function ($oImage) use ($_this, $sDir, $sFile, $aParamsSave) {

$sFormat = ($_this->getParam('format_auto') && $_this->getFormat()) ? $_this->getFormat() : $_this->getParam('format');
$sFileTmp = Config::Get('path.tmp.server') . DIRECTORY_SEPARATOR . func_generator(20);
$_this->internalSave($sFileTmp, $sFormat);
$_this->internalSave($sFileTmp, $sFormat, $aParamsSave);

$sFile .= '.' . $sFormat;
return $_this->Image_SaveFileSmart($sFileTmp, $sDir, $sFile, 0666, true);
Expand Down Expand Up @@ -473,17 +475,22 @@ public function watermark($sFile, $mPosition)
*
* @param string $sFile Полный путь до локального файла
* @param string $sFormat Формат сохранения: jpg, gif, png
* @param array $aParamsSave Дополнительные опции сохранения, например, не делать вотермарк
*
* @return bool
*/
public function internalSave($sFile, $sFormat)
public function internalSave($sFile, $sFormat, $aParamsSave = array())
{
if (!$oImage = $this->getImage()) {
return false;
}
$aParamsSave = array_merge(array(
'skip_watermark' => false
), $aParamsSave);
if ($this->getParam('interlace')) {
$this->interlace($this->getParam('interlace'));
}
if ($this->getParam('watermark_use')) {
if (!$aParamsSave['skip_watermark'] and $this->getParam('watermark_use')) {
if ($this->getParam('watermark_type') == 'image') {
$this->watermark($this->getParam('watermark_image'), $this->getParam('watermark_position'));
}
Expand Down

0 comments on commit 54f76be

Please sign in to comment.