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

Getting applyMask to work #449

Merged
merged 1 commit into from
Jan 6, 2017
Merged

Conversation

kasuparu
Copy link

I could not make GD\Image::applyMask() to work as described in Reflection example in http://www.slideshare.net/avalanche123/introduction-toimagine so I made some fixes.

  1. It still supports only RGB palette for mask, but now accounts average between colors.
  2. It does change image if its transparency is less than 0.5.

@spenibus
Copy link

Shouldn't the white parts of the mask stay visible and the black parts disappear ? While this seems to fix applyMask(), the mask seems to be applied backwards.

The following seems more appropriate:

$whiteAmount = ($maskColor->getValue(ColorInterface::COLOR_RED) + $maskColor->getValue(ColorInterface::COLOR_GREEN) + $maskColor->getValue(ColorInterface::COLOR_BLUE)) / 3 / 255;
$round       = (int) round($color->getAlpha() * $whiteAmount);

Using $blackAmount:
php-imagine-applymask-using-blackamount-20150731-1831-gmt

Using $whiteAmount:
php-imagine-applymask-using-whiteamount-20150731-1831-gmt

@kasuparu
Copy link
Author

kasuparu commented Aug 4, 2015

"Reflection" example states that white is transparent, in other words, blacks stay and whites dissolve.

imagine-reflection

@spenibus
Copy link

spenibus commented Aug 4, 2015

I guess I can only curse at the lack of standardisation regarding image masking. This really feels counter-intuitive.

@axi
Copy link

axi commented Feb 17, 2016

Found this fix really usefull, should be merged

@burzum burzum merged commit d3d9451 into php-imagine:develop Jan 6, 2017
@rvanlaak
Copy link

rvanlaak commented Feb 3, 2017

Does this resolve the bug that applyMask did not work before (see liip/LiipImagineBundle#752)? So after this is released we can create circle thumbs again? 👍

@@ -376,7 +376,8 @@ public function applyMask(ImageInterface $mask)
$position = new Point($x, $y);
$color = $this->getColorAt($position);
$maskColor = $mask->getColorAt($position);
$round = (int) round(max($color->getAlpha(), (100 - $color->getAlpha()) * $maskColor->getRed() / 255));
$blackAmount = 1 - ($maskColor->getValue(ColorInterface::COLOR_RED) + $maskColor->getValue(ColorInterface::COLOR_GREEN) + $maskColor->getValue(ColorInterface::COLOR_BLUE)) / 3 / 255;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be tested

This was referenced Feb 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants