Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Font color #26

wants to merge 3 commits into from

Conversation

shqawe1
Copy link

@shqawe1 shqawe1 commented Aug 14, 2023

Add new function with name setFontColor to have ability to change font color. and this function accepting just RGB & RGBA format.

Example:

`$watermark->setFont('Arial')
->setFontSize(36)
->setOpacity(.4)
->setRotate(330)
->setFontColor('rgba(255, 255, 255,0)')
->setOffset(-80, 200)
->setPosition(Watermark::POSITION_RIGHT);

$text = "ajaxray.com";
$watermark->withText($text, DIR.'/img/result_simple.jpg');`

Adding two functions on to change font color and another for convert rgba color to accept format for ImageMagick command .
Adding format font color function to  getDuelTextColor function.
Add miss function to prepare font color
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) {
Copy link
Owner

Choose a reason for hiding this comment

The 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?

Copy link
Author

Choose a reason for hiding this comment

The 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:

if (!empty($rgb[4])) {

*/
public function setFontColor($fontColor)
{
$this->options['fontcolor'] = $this->_prepareColorForWaterMark($fontColor);
Copy link
Owner

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.

Suggested change
$this->options['fontcolor'] = $this->_prepareColorForWaterMark($fontColor);
$this->options['fontcolor'] = $this->_prepareColorForWaterMark($fontColor);
return $this;

Copy link
Author

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.

} else {
$hex = str_replace('#', '', $hex);

if (utf8_strlen($hex) == 3) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utf8_strlen function is not found. Can we use mb_strlen() instead?

Copy link
Author

Choose a reason for hiding this comment

The 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.

@ajaxray
Copy link
Owner

ajaxray commented Aug 15, 2023

Assalamualaikum @shqawe1 ,

I am very happy that you've solved it and want to share the solution! 🤗

I was trying to test it and found a few tiny issues.
If you can manage a few more minutes, can you please look into the points I've mentioned above?

Also, if you could list all the supported color formats that will work after merging this, that would be very much helpful.
I'll use the list to add to the readme file.

Thanks a lot, brother!
Your contribution is very much appreciated! ❤️

@shqawe1
Copy link
Author

shqawe1 commented Aug 15, 2023

First of all i want you to accept my apologize for these mistakes because i wrote it quickly as copy paste from my project.
And i reply with correct code for each one of the issue and i hope it will work without any issue.

About the color format the code accept rgb & rgba formats.
rgb(255, 255, 255)

rgba(255, 255, 255, 0.4)

@jacob-gardiner
Copy link

Are there any plans to merge this? I want to use it for a project but could not do so without this functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants