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

applyMask() not working #750

Closed
retosteffen opened this issue Jul 4, 2016 · 6 comments
Closed

applyMask() not working #750

retosteffen opened this issue Jul 4, 2016 · 6 comments

Comments

@retosteffen
Copy link

I tried to create a new Filter that transforms square thumbnails into round thumbnails with a mask on a PNG file.
(If I'm correct transforming jpg into png files isn't yet implemented in this bundle.)
But the applyMask() doesn't work, it just gives me back the same file.
Is this not yet part of the bundle or am I doing something wrong?

@alexwilson
Copy link
Collaborator

Hey, thanks for reporting this, sorry about the delay - Is this still an issue?

If so, would you be able to contribute a failing test case?

@retosteffen
Copy link
Author

Hi,
Sorry was travelling but will check it this is still an issue (it was a month ago) and provide a test case this week.

@retosteffen
Copy link
Author

@antoligy
Here is the script that doesn't work for me. It's supposed to make a PNG image square and then mask it with a circle so that the outer part of the circle is transparent.
If I export the mask as the image it gives the "right" result, i.e. a black circle with a transparent background.

use Imagine\Filter\Basic\Thumbnail;
use Imagine\Image\Box;
use Imagine\Image\BoxInterface;
use Imagine\Image\ImageInterface;
use Imagine\Image\Palette\Color;
use Imagine\Image\Palette\RGB;
use Imagine\Filter\FilterInterface;
use Imagine\Image\Point\Center;
use Imagine\Filter\Basic\ApplyMask;

class CircleThumbnailFilter implements FilterInterface
{
    private $imagine;



    public function __construct($imagine, BoxInterface $size)
    {
        $this->imagine = $imagine;
        $this->size = $size;
    }

    public function apply(ImageInterface $image)
    {
        // create a square thumbnail
        $thumbnail = $image->thumbnail(
            $this->size,
            ImageInterface::THUMBNAIL_OUTBOUND
        );

        // create a new image to hold our mask
        // make the background white
        $palette = new RGB();
        $white=$palette->color('#FFFFFF',0);
        $black=$palette->color('#000000',100);
        $mask = $this->imagine->create($this->size, $white);

        // draw a black circle at the center of our new image
        // use $this->size to make it full width and height
        $mask->draw()
            ->ellipse(
                new Center($this->size),
                $this->size,
                $black,
                true
            );

        // apply the mask to the thumbnail and return it
        return $thumbnail->applyMask($mask);



    }
}

Let me know if you need anything else.
Thanks!

@alexwilson
Copy link
Collaborator

Thanks for this, I'll take a look most likely this evening! 😄

@rvanlaak
Copy link

rvanlaak commented Feb 3, 2017

ping @antoligy ;)

@michellesanver
Copy link
Contributor

@retosteffen It seems that this issue got forgotten. Easily happens! Since it's so old and not mentioned much anymore, I have decided to close it. If it's still an issue for you, or anyone, please open a new issue so that we know it's a current problem to debug.

And thanks @antoligy for the intention to fix this, if you have any more context to this issue and would like to contribute a new issue (Even if not working on a PR), I'd be super grateful. Thanks! :)

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

No branches or pull requests

4 participants