PHRAS-3580 WIP

new "watermark text" setting to subdef
This commit is contained in:
jygaulier
2021-11-15 17:03:52 +01:00
parent 8d49800c73
commit e487553d9c
8 changed files with 108 additions and 30 deletions

View File

@@ -23,6 +23,7 @@ class Image extends Provider
const OPTION_FLATTEN = 'flatten'; const OPTION_FLATTEN = 'flatten';
const OPTION_ICODEC = 'icodec'; const OPTION_ICODEC = 'icodec';
const OPTION_WATERMARK = 'watermark'; const OPTION_WATERMARK = 'watermark';
const OPTION_WATERMARKTEXT = 'watermarktext';
protected $options = []; protected $options = [];
@@ -37,6 +38,7 @@ class Image extends Provider
$this->registerOption(new OptionType\Range($this->translator->trans('Quality'), self::OPTION_QUALITY, 0, 100, 75)); $this->registerOption(new OptionType\Range($this->translator->trans('Quality'), self::OPTION_QUALITY, 0, 100, 75));
$this->registerOption(new OptionType\Enum('Image Codec', self::OPTION_ICODEC, array('jpeg', 'png', 'tiff'), 'jpeg')); $this->registerOption(new OptionType\Enum('Image Codec', self::OPTION_ICODEC, array('jpeg', 'png', 'tiff'), 'jpeg'));
$this->registerOption(new OptionType\Boolean($this->translator->trans('Watermark'), self::OPTION_WATERMARK, false)); $this->registerOption(new OptionType\Boolean($this->translator->trans('Watermark'), self::OPTION_WATERMARK, false));
$this->registerOption(new OptionType\Text($this->translator->trans('Watermark text'), self::OPTION_WATERMARKTEXT, ''));
} }
public function getType() public function getType()

View File

@@ -17,6 +17,7 @@ interface OptionType
const TYPE_ENUM = 'Enum'; const TYPE_ENUM = 'Enum';
const TYPE_BOOLEAN = 'Boolean'; const TYPE_BOOLEAN = 'Boolean';
const TYPE_MULTI = 'Multi'; const TYPE_MULTI = 'Multi';
const TYPE_TEXT = 'Text';
public function getDisplayName(); public function getDisplayName();

View File

@@ -0,0 +1,64 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2016 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Media\Subdef\OptionType;
class Text implements OptionType
{
protected $name;
protected $displayName;
protected $defaultValue;
protected $value;
public function __construct($displayName, $name, $defaultValue = '')
{
$this->displayName = $displayName;
$this->name = $name;
$this->defaultValue = $defaultValue;
if ($defaultValue) {
$this->setValue($defaultValue);
}
}
public function getDisplayName()
{
return $this->displayName;
}
public function getType()
{
return self::TYPE_TEXT;
}
public function getName()
{
return $this->name;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
if (!$value) {
$this->value = '';
return $this;
}
$this->value = $value;
return $this;
}
}

View File

@@ -21,6 +21,7 @@ use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreationEvent;
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository; use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
use Alchemy\Phrasea\Filesystem\FilesystemService; use Alchemy\Phrasea\Filesystem\FilesystemService;
use Alchemy\Phrasea\Media\Subdef\OptionType\Boolean; use Alchemy\Phrasea\Media\Subdef\OptionType\Boolean;
use Alchemy\Phrasea\Media\Subdef\OptionType\Text;
use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification; use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification;
use Exception; use Exception;
use Imagine\Image\ImagineInterface; use Imagine\Image\ImagineInterface;
@@ -293,11 +294,14 @@ class SubdefGenerator
if($subdef_class->getSpecs() instanceof Image) { if($subdef_class->getSpecs() instanceof Image) {
/** @var Subdef\Image $image */ /** @var Subdef\Image $image */
$image = $subdef_class->getSubdefType(); $image = $subdef_class->getSubdefType();
/** @var Boolean $o */ /** @var Boolean $wm */
$o = $image->getOption(Subdef\Image::OPTION_WATERMARK); $wm = $image->getOption(Subdef\Image::OPTION_WATERMARK);
if($o->getValue()) { if($wm->getValue()) {
// we must watermark the file // we must watermark the file
$this->wartermarkImageFile($pathdest); /** @var Text $wmt */
$wmt = $image->getOption(Subdef\Image::OPTION_WATERMARKTEXT);
$this->wartermarkImageFile($pathdest, $wmt->getValue());
} }
} }
@@ -320,7 +324,7 @@ class SubdefGenerator
} }
} }
private function wartermarkImageFile($filepath) private function wartermarkImageFile(string $filepath, string $watermarkText)
{ {
static $palette; static $palette;
@@ -342,30 +346,31 @@ class SubdefGenerator
$draw->line(new Point(0, $in_h - 2), new Point($in_w - 2, 0), $black); $draw->line(new Point(0, $in_h - 2), new Point($in_w - 2, 0), $black);
$draw->line(new Point(1, $in_h - 1), new Point($in_w - 1, 1), $white); $draw->line(new Point(1, $in_h - 1), new Point($in_w - 1, 1), $white);
/* if($watermarkText) {
$fsize = max(8, (int)(max($in_w, $in_h) / 30)); $fsize = max(8, (int)(max($in_w, $in_h) / 30));
$fonts = [ $fonts = [
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $black), $imagine->font(__DIR__ . '/../../../../resources/Fonts/arial.ttf', $fsize, $black),
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $white) $imagine->font(__DIR__ . '/../../../../resources/Fonts/arial.ttf', $fsize, $white)
]; ];
$testbox = $fonts[0]->box($collname, 0); $testbox = $fonts[0]->box($watermarkText, 0);
$tx_w = min($in_w, $testbox->getWidth()); $tx_w = min($in_w, $testbox->getWidth());
$tx_h = min($in_h, $testbox->getHeight()); $tx_h = min($in_h, $testbox->getHeight());
$x0 = max(1, ($in_w - $tx_w) >> 1); $x0 = max(1, ($in_w - $tx_w) >> 1);
$y0 = max(1, ($in_h - $tx_h) >> 1); $y0 = max(1, ($in_h - $tx_h) >> 1);
for ($i = 0; $i <= 1; $i++) { for ($i = 0; $i <= 1; $i++) {
$x = max(1, ($in_w >> 2) - ($tx_w >> 1)); $x = max(1, ($in_w >> 2) - ($tx_w >> 1));
$draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i)); $draw->text($watermarkText, $fonts[$i], new Point($x - $i, $y0 - $i));
$x = max(1, $in_w - $x - $tx_w); $x = max(1, $in_w - $x - $tx_w);
$draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i)); $draw->text($watermarkText, $fonts[$i], new Point($x - $i, $y0 - $i));
$y = max(1, ($in_h >> 2) - ($tx_h >> 1)); $y = max(1, ($in_h >> 2) - ($tx_h >> 1));
$draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i)); $draw->text($watermarkText, $fonts[$i], new Point($x0 - $i, $y - $i));
$y = max(1, $in_h - $y - $tx_h); $y = max(1, $in_h - $y - $tx_h);
$draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i)); $draw->text($watermarkText, $fonts[$i], new Point($x0 - $i, $y - $i));
}
} }
*/
$in_image->save($filepath); $in_image->save($filepath);
} }

View File

@@ -141,6 +141,9 @@ class databox_subdef
if ($sd->watermark) { if ($sd->watermark) {
$image->setOptionValue(Image::OPTION_WATERMARK, p4field::isyes($sd->watermark)); $image->setOptionValue(Image::OPTION_WATERMARK, p4field::isyes($sd->watermark));
} }
if ($sd->watermarktext) {
$image->setOptionValue(Image::OPTION_WATERMARKTEXT, $sd->watermarktext);
}
return $image; return $image;
} }
/** /**

View File

@@ -285,7 +285,7 @@ class recordutils_image
$txtline = $texts->item($i)->nodeValue; $txtline = $texts->item($i)->nodeValue;
if ($txtline != '') { if ($txtline != '') {
$wrap = static::wrap($imagine, $fontsize, 0, __DIR__ . '/arial.ttf', $txtline, $text_width); $wrap = static::wrap($imagine, $fontsize, 0, __DIR__ . '/../../../resources/Fonts/arial.ttf', $txtline, $text_width);
$txtblock[] = [ $txtblock[] = [
'fontsize' => $fontsize, 'fontsize' => $fontsize,
'fontcolor' => $xmlToColor($texts->item($i)->getAttribute('color'), [0, 0, 0]), 'fontcolor' => $xmlToColor($texts->item($i)->getAttribute('color'), [0, 0, 0]),
@@ -327,7 +327,7 @@ class recordutils_image
$draw = $imfg->draw(); $draw = $imfg->draw();
$txt_ypos = 0; $txt_ypos = 0;
foreach ($txtblock as $block) { foreach ($txtblock as $block) {
$font = $imagine->font(__DIR__ . '/arial.ttf', $block['fontsize'], $block['fontcolor']); $font = $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $block['fontsize'], $block['fontcolor']);
foreach ($block['lines'] as $line) { foreach ($block['lines'] as $line) {
if ($line['t'] != '') { if ($line['t'] != '') {
$draw->text($line['t'], $font, new Point($logo_reswidth, $txt_ypos), 0); $draw->text($line['t'], $font, new Point($logo_reswidth, $txt_ypos), 0);
@@ -486,8 +486,8 @@ class recordutils_image
$fsize = max(8, (int)(max($in_w, $in_h) / 30)); $fsize = max(8, (int)(max($in_w, $in_h) / 30));
$fonts = [ $fonts = [
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $black), $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $fsize, $black),
$imagine->font(__DIR__ . '/arial.ttf', $fsize, $white) $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $fsize, $white)
]; ];
$testbox = $fonts[0]->box($collname, 0); $testbox = $fonts[0]->box($collname, 0);
$tx_w = min($in_w, $testbox->getWidth()); $tx_w = min($in_w, $testbox->getWidth());

BIN
resources/Fonts/arial.ttf Normal file

Binary file not shown.

View File

@@ -538,6 +538,9 @@
</td> </td>
<td style="width:250px;"> <td style="width:250px;">
{% set extradata = '' %} {% set extradata = '' %}
{% if option.getType() == constant('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType::TYPE_TEXT') %}
<input name="{{ varname }}" type="text" value="{{ option.getValue() }}">
{% endif %}
{% if option.getType() == constant('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType::TYPE_RANGE') %} {% if option.getType() == constant('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType::TYPE_RANGE') %}
<div style="width:250px;" <div style="width:250px;"
id="slider{{ subdefgroup }}{{ subdefname }}{{ subdefType.getType() }}{{ option.getName() }}"></div> id="slider{{ subdefgroup }}{{ subdefname }}{{ subdefType.getType() }}{{ option.getName() }}"></div>