Jump to content

plugin to crop to image (with transparency)


Recommended Posts

I cannot find a plugin or command to resize the image surface to the closest rectangle around the "solid" image.

For example, if i draw a small circle in the middle of the canvas, I would like to be able to crop it without going to select tool, adjusting etc.

anybody can help?

thank you!!!

Edited by nery89
Link to comment
Share on other sites

no-no-no, i need to CROP (thank you, i just edited the post title) the transparent area to save the most space i can.

 

for clarity sake i upload an example:

imagine i have the BEFORE image, which is a small body in a transparent big background.

what the function / plugin etc, should accomplish is cropping the image to get the AFTER image.

AFTER image fill all the rectangle so there is at least 1 pixel non-transparet on each edge.

sorry if i didn't explain very well, english is not my native language! thank you all!

 

P.S. - the resul can be achived with this commands:

magick wand -> select external transparent zone with 0% tolerance -> ctrl+i (invert selection) -> crop

sample_before_crop.png

sample_after_crop.png

Edited by nery89
Link to comment
Share on other sites

3 hours ago, Eli said:

I think there is a plugin made by @MJW that does that but I can not find it. :(

 

Edit : Object Pruner or perhaps Unselected Rectangle Keeper.

 

You may be thinking of the awkwardly-named Unselected Rectangle Keeper. It's intended to help crop colored images on a flat-colored background. Unfortunately, I don' think it helps for this request. I think @nery89's P.S. comment is really the best solution at this time.

 

The original request, as I understand it, isn't possible for a plugin, since plugins can't change the size of the canvas.

Link to comment
Share on other sites

I added a copy of the source code to my head post in "Unselected Rectangle Keeper" so nery89 can see how simple the code is to do what it does.

 

It would be simpler, still, if I wrote it today. All the "firstTime" code could be done in CodeLab's PreRender, without the firstTime flag or the locks, like this:

 

        void PreRender(Surface src, Surface dst)
        {
            PdnRegion selectionRegion = EnvironmentParameters.GetSelection(src.Bounds);
            Rectangle selection = selectionRegion.GetBoundsInt();

            int l = int.MaxValue, r = -1, t = int.MaxValue, b = -1;
            for (int y = selection.Top; y < selection.Bottom; y++)
            {
                for (int x = selection.Left; x < selection.Right; x++)
                {
                    if (!selectionRegion.IsVisible(x, y))
                    {
                        if (x < l)
                            l = x;
                        if (x > r)
                            r = x;
                        if (t == int.MaxValue)
                            t = y;
                        b = y;
                    }
                }
            }
                          
            right = r; left = l; top = t; bottom = b;
        }


 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...