diff --git a/lib/Alchemy/Phrasea/Media/Subdef/Image.php b/lib/Alchemy/Phrasea/Media/Subdef/Image.php index 7239f3e01d..e9ad88721b 100644 --- a/lib/Alchemy/Phrasea/Media/Subdef/Image.php +++ b/lib/Alchemy/Phrasea/Media/Subdef/Image.php @@ -23,6 +23,7 @@ class Image extends Provider const OPTION_FLATTEN = 'flatten'; const OPTION_ICODEC = 'icodec'; const OPTION_WATERMARK = 'watermark'; + const OPTION_WATERMARKTEXT = 'watermarktext'; 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\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\Text($this->translator->trans('Watermark text'), self::OPTION_WATERMARKTEXT, '')); } public function getType() diff --git a/lib/Alchemy/Phrasea/Media/Subdef/OptionType/OptionType.php b/lib/Alchemy/Phrasea/Media/Subdef/OptionType/OptionType.php index 3a451fa043..b3797160ca 100644 --- a/lib/Alchemy/Phrasea/Media/Subdef/OptionType/OptionType.php +++ b/lib/Alchemy/Phrasea/Media/Subdef/OptionType/OptionType.php @@ -17,6 +17,7 @@ interface OptionType const TYPE_ENUM = 'Enum'; const TYPE_BOOLEAN = 'Boolean'; const TYPE_MULTI = 'Multi'; + const TYPE_TEXT = 'Text'; public function getDisplayName(); diff --git a/lib/Alchemy/Phrasea/Media/Subdef/OptionType/Text.php b/lib/Alchemy/Phrasea/Media/Subdef/OptionType/Text.php new file mode 100644 index 0000000000..74cbe0551a --- /dev/null +++ b/lib/Alchemy/Phrasea/Media/Subdef/OptionType/Text.php @@ -0,0 +1,64 @@ +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; + } +} diff --git a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php index 0484136257..fe1344210e 100644 --- a/lib/Alchemy/Phrasea/Media/SubdefGenerator.php +++ b/lib/Alchemy/Phrasea/Media/SubdefGenerator.php @@ -21,6 +21,7 @@ use Alchemy\Phrasea\Core\Event\Record\SubDefinitionsCreationEvent; use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository; use Alchemy\Phrasea\Filesystem\FilesystemService; use Alchemy\Phrasea\Media\Subdef\OptionType\Boolean; +use Alchemy\Phrasea\Media\Subdef\OptionType\Text; use Alchemy\Phrasea\Media\Subdef\Specification\PdfSpecification; use Imagine\Image\ImagineInterface; use Imagine\Image\Palette\RGB; @@ -292,11 +293,14 @@ class SubdefGenerator if($subdef_class->getSpecs() instanceof Image) { /** @var Subdef\Image $image */ $image = $subdef_class->getSubdefType(); - /** @var Boolean $o */ - $o = $image->getOption(Subdef\Image::OPTION_WATERMARK); - if($o->getValue()) { + /** @var Boolean $wm */ + $wm = $image->getOption(Subdef\Image::OPTION_WATERMARK); + if($wm->getValue()) { + // we must watermark the file - $this->wartermarkImageFile($pathdest); + /** @var Text $wmt */ + $wmt = $image->getOption(Subdef\Image::OPTION_WATERMARKTEXT); + $this->wartermarkImageFile($pathdest, $wmt->getValue()); } } @@ -319,7 +323,7 @@ class SubdefGenerator } } - private function wartermarkImageFile($filepath) + private function wartermarkImageFile(string $filepath, string $watermarkText) { static $palette; @@ -341,30 +345,31 @@ class SubdefGenerator $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); - /* - $fsize = max(8, (int)(max($in_w, $in_h) / 30)); - $fonts = [ - $imagine->font(__DIR__ . '/arial.ttf', $fsize, $black), - $imagine->font(__DIR__ . '/arial.ttf', $fsize, $white) - ]; - $testbox = $fonts[0]->box($collname, 0); - $tx_w = min($in_w, $testbox->getWidth()); - $tx_h = min($in_h, $testbox->getHeight()); + if($watermarkText) { + $fsize = max(8, (int)(max($in_w, $in_h) / 30)); + $fonts = [ + $imagine->font(__DIR__ . '/../../../../resources/Fonts/arial.ttf', $fsize, $black), + $imagine->font(__DIR__ . '/../../../../resources/Fonts/arial.ttf', $fsize, $white) + ]; + $testbox = $fonts[0]->box($watermarkText, 0); + $tx_w = min($in_w, $testbox->getWidth()); + $tx_h = min($in_h, $testbox->getHeight()); - $x0 = max(1, ($in_w - $tx_w) >> 1); - $y0 = max(1, ($in_h - $tx_h) >> 1); - for ($i = 0; $i <= 1; $i++) { - $x = max(1, ($in_w >> 2) - ($tx_w >> 1)); - $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i)); - $x = max(1, $in_w - $x - $tx_w); - $draw->text($collname, $fonts[$i], new Point($x - $i, $y0 - $i)); + $x0 = max(1, ($in_w - $tx_w) >> 1); + $y0 = max(1, ($in_h - $tx_h) >> 1); + for ($i = 0; $i <= 1; $i++) { + $x = max(1, ($in_w >> 2) - ($tx_w >> 1)); + $draw->text($watermarkText, $fonts[$i], new Point($x - $i, $y0 - $i)); + $x = max(1, $in_w - $x - $tx_w); + $draw->text($watermarkText, $fonts[$i], new Point($x - $i, $y0 - $i)); - $y = max(1, ($in_h >> 2) - ($tx_h >> 1)); - $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i)); - $y = max(1, $in_h - $y - $tx_h); - $draw->text($collname, $fonts[$i], new Point($x0 - $i, $y - $i)); + $y = max(1, ($in_h >> 2) - ($tx_h >> 1)); + $draw->text($watermarkText, $fonts[$i], new Point($x0 - $i, $y - $i)); + $y = max(1, $in_h - $y - $tx_h); + $draw->text($watermarkText, $fonts[$i], new Point($x0 - $i, $y - $i)); + } } - */ + $in_image->save($filepath); } diff --git a/lib/classes/databox/subdef.php b/lib/classes/databox/subdef.php index 0fb37c1c79..d6b6fcaf7f 100644 --- a/lib/classes/databox/subdef.php +++ b/lib/classes/databox/subdef.php @@ -141,6 +141,9 @@ class databox_subdef if ($sd->watermark) { $image->setOptionValue(Image::OPTION_WATERMARK, p4field::isyes($sd->watermark)); } + if ($sd->watermarktext) { + $image->setOptionValue(Image::OPTION_WATERMARKTEXT, $sd->watermarktext); + } return $image; } /** diff --git a/lib/classes/recordutils/image.php b/lib/classes/recordutils/image.php index a7213d89f3..173417b4ea 100644 --- a/lib/classes/recordutils/image.php +++ b/lib/classes/recordutils/image.php @@ -285,7 +285,7 @@ class recordutils_image $txtline = $texts->item($i)->nodeValue; 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[] = [ 'fontsize' => $fontsize, 'fontcolor' => $xmlToColor($texts->item($i)->getAttribute('color'), [0, 0, 0]), @@ -327,7 +327,7 @@ class recordutils_image $draw = $imfg->draw(); $txt_ypos = 0; 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) { if ($line['t'] != '') { $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)); $fonts = [ - $imagine->font(__DIR__ . '/arial.ttf', $fsize, $black), - $imagine->font(__DIR__ . '/arial.ttf', $fsize, $white) + $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $fsize, $black), + $imagine->font(__DIR__ . '/../../../resources/Fonts/arial.ttf', $fsize, $white) ]; $testbox = $fonts[0]->box($collname, 0); $tx_w = min($in_w, $testbox->getWidth()); diff --git a/resources/Fonts/arial.ttf b/resources/Fonts/arial.ttf new file mode 100644 index 0000000000..ff0815cd8c Binary files /dev/null and b/resources/Fonts/arial.ttf differ diff --git a/templates/web/admin/subdefs.html.twig b/templates/web/admin/subdefs.html.twig index f3bc871679..7beaa6bea2 100644 --- a/templates/web/admin/subdefs.html.twig +++ b/templates/web/admin/subdefs.html.twig @@ -538,6 +538,9 @@ {% set extradata = '' %} + {% if option.getType() == constant('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType::TYPE_TEXT') %} + + {% endif %} {% if option.getType() == constant('\\Alchemy\\Phrasea\\Media\\Subdef\\OptionType\\OptionType::TYPE_RANGE') %}