Package: bordercrop
bordercropA black borders cropping moduleCrop the black borders from any image in a single line of code!Getting StartedThese instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.PrerequisitesYou will need Python 3 to use this module# vermin outputMinimumrequiredversions:3.2
Incompatibleversions:2According to Vermin (--backport typing), Python 3.2 is needed for the backport of typing but some may say that it is available for python versions higher than 3.0Always check if your Python version works withbordercropbefore using it in productionInstallingOption 1: From PyPIpipinstallbordercropOption 2: From Gitpipinstallhttps://github.com/Animenosekai/bordercropYou can check if you successfully installed it by printing out its version:$python-c"import bordercrop; print(bordercrop.__version__)"# output:bordercropv1.0.0or just:$bordercrop--version# output:bordercropv1.0.0UsageYou can use bordercrop in Python by importing it in your script:importbordercropcropped_image=bordercrop.crop("https://i.imgur.com/lhQe6Bq.jpg")cropped_image.show()# show the cropped imageLeaving everything with the default values, you may get images with no crop or with no size (entirely cropped).I recommend testing and tweaking the MINIMUM_THRESHOLD_HITTING and MINIMUM_ROWS values according to your picture (a big picture needs more minimum rows and more pixels to hit before counting a row as dark).CLI usageYou can use bordercrop in other apps by accessing it through the CLI version:$bordercrop--image"https://i.ytimg.com/vi/e_53PHZwQH4/hqdefault.jpg"--output"cropped.jpg"outputAs a Python moduleThe given image can be a filepath (str, bytes or Path), an URL (which will be downloaded) or a PIL.Image.Image instancecrop()Autocrops the black borders from the given imageArgs:image: the given image, it can be a filepath (str, bytes or Path), an URL (which will be downloaded), a BytesIO or a PIL.Image.Image instanceTHRESHOLD: the black threshold (0 is black while 225 is white)MINIMUM_THRESHOLD_HITTING: the number of pixels in a row which needs to hit the threshold to count the row as dark (ex: if 5 is given and there is only 4 black pixels in the row, the row won't be counted as black)MINIMUM_ROWS: the minimum row requirement to count a border (ex: if set to 3, 3 rows need to consecutively be black to count it as a border)Returns:APIL.Image.Imageinstance containing the cropped imageborders()Gives back the bounding box of the image without the black bordersArgs:image: the given image, it can be a filepath (str, bytes or Path), an URL (which will be downloaded), a BytesIO or a PIL.Image.Image instanceTHRESHOLD: the black threshold (0 is black while 225 is white)MINIMUM_THRESHOLD_HITTING: the number of pixels in a row which needs to hit the threshold to count the row as dark (ex: if 5 is given and there is only 4 black pixels in the row, the row won't be counted as black)MINIMUM_ROWS: the minimum row requirement to count a border (ex: if set to 3, 3 rows need to consecutively be black to count it as a border)Returns:A tuple containing the coordinates (LEFT, TOP, RIGHT, BOTTOM)get_image()Gives back the given image as a PIL.Image.Image instanceMostly used internally, it can be useful sometimes.Args:image: the given image, it can be a filepath (str, bytes or Path), an URL (which will be downloaded), a BytesIO or a PIL.Image.Image instanceReturns:A PIL.Image.Image instance containing the given imageExceptionsAll of the excpetions inherit from theBordercropExceptionAWrongTypeexception can be raised if the wrong type of image is givenDeploymentThis module is currently in development and might contain bugs.Feel free to use it in production if you feel like it is suitable for your production even if you may encounter issues.Built WithPillow- To manipulate imagesAuthorsAnime no Sekai-Initial work-AnimenosekaiLicenseThis project is licensed under the MIT License - see theLICENSEfile for more details