Crop Images
This program takes a directory of photos and crops pixels off of the image's edges. One may use this program to remove scanning borders.
Python (with os module), ImageMagick
#REQUIRES IMAGEMAGIC TO BE INSTALLED ON MACHINE
import os
directory = "#DIRECTORY OF PHOTO SCANS#"
files = os.listdir(directory)
files.sort()
# This function crops pixels off of the edges of an image.
def crop (file, file_path):
# Change the "-shave 2x3" to change the amount of pixels it crops.
bashCommand = "Convert " + str(file_path) + " -shave 2x3 " + str(file_path)
os.system(bashCommand)
print(str(file) + " cropped")
# The program starts here and crops the edges off of each image in the directory.
crop_count = 0
for file in files:
if ".jpeg" or ".jpg" or ".png" in str(file):
try:
file_path = directory + "/" + str(file)
crop(file, file_path)
crop_count += 1
except:
print(file_path)
print('\33[101m' + "*****ERROR*****" + '\x1b[0m')
print(str(crop_count) + " photos cropped!")