Created
January 14, 2014 08:48
-
-
Save Micka33/8415196 to your computer and use it in GitHub Desktop.
script using imageMagic to resize only the images that are bigger than 1460x841
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from subprocess import call | |
import time | |
from datetime import datetime | |
import calendar | |
import re | |
## | |
## Library | |
## | |
def tell(array_of_strings): | |
print "###############" | |
if not isinstance(array_of_strings, basestring): | |
for string in array_of_strings: | |
print "###############"+string | |
else: | |
print "###############"+array_of_strings | |
print "###############" | |
def cmd(array): | |
print '==>'+(' '.join(array)) | |
call(array) | |
## | |
## Process | |
## | |
def rename_folders(folderpath): | |
tell("Renaming folders in "+folderpath) | |
for dirname, dirnames, filenames in os.walk(folderpath): | |
for subdirname in dirnames: | |
new_subdir = subdirname.replace(' ', '_') | |
new_subdir = new_subdir.replace('-', '_') | |
cmd(['mv', os.path.join(dirname, subdirname), os.path.join(dirname, new_subdir)]) | |
def resize(folderpath): | |
i = 0 | |
for dirname, dirnames, filenames in os.walk(folderpath): | |
tell("resizing images") | |
#Getting the images and check for their date | |
for filename in filenames: | |
if re.search(".+\.png$", filename, re.IGNORECASE): | |
i += 1 | |
newName = os.path.join(dirname, str(i)+'temp.png')#.replace(' ', '\ ') | |
oldname = os.path.join(dirname, filename)#.replace(' ', '\ ') | |
cmd(["convert", oldname, '-resize', '1460x841>', newName]) | |
cmd(["rm", oldname]) | |
cmd(["mv", newName, oldname]) | |
## | |
## Main | |
## | |
#timestamp | |
def main(folder): | |
rename_folders(folder) | |
resize(folder) | |
## | |
## First call | |
## | |
main('./tuto_2_opti') | |
main('./tuto_3_opti') | |
main('./tuto_4_opti') | |
main('./tuto_5_opti') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment