4 lines going A to B, first pixel which is not color black or transparent will be the minimum / maximum distance to crop(edited)
18:03
you can also do it with 2 lines, and for each line, get the first instance and last instance of a pixel being different and boom, comparision, calculation and voila
18:04
got a rectangle which has it's position and size. you can now make a program where you crop the image based off of the rectangle's info and you have a picture, nicely cropped