-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Font color #26
base: master
Are you sure you want to change the base?
Font color #26
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,7 @@ class Watermark | |
'opacity' => 0.3, | ||
'rotate' => 0, | ||
'style' => 1, // STYLE_IMG_DISSOLVE or STYLE_TEXT_BEVEL | ||
'fontcolor' => '#ffffff', | ||
]; | ||
|
||
public function __construct(string $source) | ||
|
@@ -160,6 +161,18 @@ public function setFontSize(int $fontSize): self | |
return $this; | ||
} | ||
|
||
/** | ||
* Font color. Should to be in rgb or rgba format | ||
* | ||
* @param string $fontColor | ||
* @return Watermark | ||
* Added by [email protected] | ||
*/ | ||
public function setFontColor($fontColor) | ||
{ | ||
$this->options['fontcolor'] = $this->_prepareColorForWaterMark($fontColor); | ||
} | ||
|
||
/** | ||
* @param float $opacity Between .1 (very transparent) to .9 (almost opaque). | ||
*/ | ||
|
@@ -212,4 +225,58 @@ private function ensureWritable(string $dirPath): void | |
throw new \InvalidArgumentException("The specified destination $dirPath is not writable!"); | ||
} | ||
} | ||
|
||
/** | ||
* Prepare color for watermark command line | ||
*/ | ||
private function _prepareColorForWaterMark($color) | ||
{ | ||
$hexColor = $this->_colorToRGB($color); | ||
|
||
$opecity = $this->options['opacity']; | ||
|
||
$rgba = "rgba\\(" . $hexColor[0] . "," . $hexColor[1] . "," . $hexColor[2] . "," . $opecity . "\\)"; | ||
return $rgba; | ||
} | ||
|
||
private function _colorToRGB($hex) | ||
{ | ||
$hex = strtolower($hex); | ||
|
||
if (strpos($hex, 'rgba') !== false) { | ||
preg_match('/^rgba?\((\d+),\s*(\d+),\s*(\d+)(?:,\s*(\d+(?:\.\d+)?))?\)$/i', $hex, $rgb); | ||
|
||
if ($rgb) { | ||
if (!empty($rgb[4]) && \XF::options()->up_wm_opecity === 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. XF is not found. Can you please use an alternative that does not require additional installation? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm sorry for that mistake maybe i forget to change that line because i use it in my project the line number 250 should be like this:
|
||
$this->setOpacity(intval(127 - 127 * $rgb[4])); | ||
} | ||
|
||
return [$rgb[1], $rgb[2], $rgb[3]]; | ||
} | ||
} | ||
|
||
if (strpos($hex, 'rgb') !== false) { | ||
preg_match('/^rgb\(\s*(\d+%?)\s*,\s*(\d+%?)\s*,\s*(\d+%?)\s*\)$/i', $hex, $rgb); | ||
|
||
if ($rgb) { | ||
return [$rgb[1], $rgb[2], $rgb[3]]; | ||
} | ||
} else { | ||
$hex = str_replace('#', '', $hex); | ||
|
||
if (utf8_strlen($hex) == 3) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't try that but to make utf8_strlen work you should to Install php-mbstring module on server and that's will solve this issue. |
||
$r = hexdec(substr($hex, 0, 1) . substr($hex, 0, 1)); | ||
$g = hexdec(substr($hex, 1, 1) . substr($hex, 1, 1)); | ||
$b = hexdec(substr($hex, 2, 1) . substr($hex, 2, 1)); | ||
} else { | ||
$r = hexdec(substr($hex, 0, 2)); | ||
$g = hexdec(substr($hex, 2, 2)); | ||
$b = hexdec(substr($hex, 4, 2)); | ||
} | ||
|
||
return [$r, $g, $b]; | ||
} | ||
|
||
return [0, 0, 0]; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this function chainable, we should return
$this
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct I'm sorry i miss that.