Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Detect boundaries within .png's - and cropping

by Fletch (Chancellor)
on Jul 08, 2020 at 07:09 UTC ( #11119027=note: print w/replies, xml ) Need Help??


in reply to Detect boundaries within .png's - and cropping

Handwavy outline.

  • Use Imager to load the image
  • Start at the top row. Assume the width of the transparent extent for both left and right is the width of the image; similarly the top and bottom is the height.
  • Walk each row and find the length of the transparent extent to the left and right
  • If that length is less than the current maximum, remember it as the new current maximum
  • At the same time you're going to want to look and make a similar determination for the extent in each column
  • After you've walked down each row you know the width of the left most and right most transparent chunks; so crop horizontally from there over. And you should also have the vertical extents as well.

The cake is a lie.
The cake is a lie.
The cake is a lie.

  • Comment on Re: Detect boundaries within .png's - and cropping

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11119027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2020-09-22 15:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (129 votes). Check out past polls.

    Notices?