Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##################################################
- # Python Cover Crop for Media Centers #
- ##################################################
- # Coded by Timscampi #
- # v0.1 (07/19/2011) - Initial release #
- # v0.2 (07/20/2011) - Added 20 presets #
- ##################################################
- # Script under GNU GPL v3 #
- # http://www.gnu.org/licenses/gpl-3.0.html #
- ##################################################
- # Imports
- from PIL import Image
- import os
- # Settings
- debugmode = 1 # Value of 0 = OFF and 1 = ON; Show useful debug messages during processing
- # List all .jpg files with same name as directory
- for dirname, dirnames, filenames in os.walk('.'):
- for filename in filenames:
- filecheck = dirname.replace(".\\","")
- if os.path.join(dirname, filename) == (dirname + "\\" + filecheck + ".jpg"):
- # Process all files matching the pattern <dirname>.jpg
- print "Processing " + os.path.join(dirname, filename)
- filepath = os.path.join(dirname, filename)
- image = Image.open(filepath)
- # Get the image dimensions
- width, height = image.size
- # Show image dimensions if debug is ON
- if debugmode == 1:
- print " Debug: Width:", width, "| Height:", height
- # Calculate dimensions of cropped image
- croppedwidth = int(width / 2.11)
- croppedheight = height
- #Presets
- #Preset SOD (SDMS, SDDE); crop 3 pixels
- if ("SDDE" in filename) or ("SDMS" in filename):
- croppedwidth = croppedwidth - 3
- print " - Preset: Soft On Demand"
- #Preset Natura High (NHDT); crop 2 pixels
- if ("NHDT" in filename):
- croppedwidth = croppedwidth - 2
- print " - Preset: Natura High"
- #Preset HTY; crop 1 pixel
- if ("HTV" in filename):
- croppedwidth = croppedwidth - 1
- print " - Preset: HTV"
- #Preset Prestige (EVO, DAY, ZER, EZD, DOM); crop 1 pixel
- if ("EVO" in filename) or ("DAY" in filename) or ("ZER" in filename) or ("EZD" in filename) or ("DOM" in filename) and (height == 522):
- croppedwidth = croppedwidth - 1
- print " - Preset: Prestige (522)"
- #Preset Prestige (DOM); overcrop a little
- if ("DOM" in filename) and (height == 488):
- croppedwidth = croppedwidth + 13
- print " - Preset: Prestige (488)"
- #Preset DIM; crop 5 pixels
- if ("DIM" in filename):
- croppedwidth = croppedwidth - 5
- print " - Preset: DIM"
- #Preset DNPD front on the left, crop 0 pixels
- if ("DNPD" in filename):
- print " - Preset: DNPD"
- #Preset CRZ; crop 5 pixels
- if ("CRZ" in filename) and (height == 541):
- croppedwidth = croppedwidth - 5
- print " - Preset: CRZ"
- #Preset FSET; crop 2 pixels
- if ("FSET" in filename) and (height == 675):
- croppedwidth = croppedwidth - 2
- print " - Preset: FSET"
- #Preset Natural High (ABC-001); Couldn't find any cover to test with
- # !!!BROKEN!!! Cannot find a cover scan
- #if ("ABC" in filename):
- # print " - Preset: FSET"
- #Preset Moodyz (MIRD dual discs); center the overcropping
- if ("MIRD" in filename) and (height == 499):
- print " - Preset: Moodyz dual discs"
- #Need a reference cover to adjust
- #Preset Opera (OPRD); crop 1 pixel
- if ("OPRD" in filename) and (height == 540):
- croppedwidth = croppedwidth - 1
- print " - Preset: Opera"
- #Preset Jade (P9); crop 2 pixels
- if ("P9" in filename) and (height == 470):
- croppedwidth = croppedwidth - 2
- print " - Preset: Jade"
- #Preset Rocket (RCT); crop 2 pixels
- if ("RCT" in filename) and (height == 471):
- croppedwidth = croppedwidth - 2
- print " - Preset: Rocket"
- #Preset Image (SIMG); crop 10 pixels
- if ("SIMG" in filename) and (height == 864):
- croppedwidth = croppedwidth - 10
- print " - Preset: Image (864)"
- #Preset Image (SIMG); crop 4 pixels
- if ("SIMG" in filename) and (height == 541):
- croppedwidth = croppedwidth - 4
- print " - Preset: Image (541)"
- #Preset Image (SVDVD); crop 2 pixels
- if ("SVDVD" in filename) and (height == 950):
- croppedwidth = croppedwidth - 4
- print " - Preset: Image (SVDVD)"
- #Preset Image (XV-65); crop 6 pixels
- if ("XV-65" in filename) and (width == 750):
- croppedwidth = croppedwidth - 6
- print " - Preset: Image (XV-65)"
- #Preset 800x538; crop 2 pixels
- if (height == 538) and (width == 800):
- croppedwidth = croppedwidth - 2
- print " - Preset: Default (800x538)"
- #Preset 800x537; crop 1 pixel
- if (height == 537) and (width == 800):
- croppedwidth = croppedwidth - 1
- print " - Preset: Default (800x537)"
- if debugmode == 1:
- print " Debug: Cropped Width:", croppedwidth, "| Cropped Height:", croppedheight
- # Let's crop the image
- if "DNPD" in filename:
- # Handling some weird inverted covers
- croptupple = [0,0,croppedwidth,height]
- else:
- croptupple = [(width - croppedwidth),0,width,height]
- if debugmode == 1:
- print " Debug: cropping dimensions:",croptupple
- croppedimage = image.crop(croptupple)
- if debugmode == 1:
- print " Debug: cropped successfully !"
- # Save both images to the folder
- folderpath = dirname + "\\folder.jpg"
- posterpath = dirname + "\\poster.jpg"
- croppedimage.save(folderpath)
- if debugmode == 1:
- print " Debug: folder.jpg saved !"
- croppedimage.save(posterpath)
- if debugmode == 1:
- print " Debug: poster.jpg saved !"
- print "Process complete."
- os.system("pause")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement