From e94e3a6da5bc47e5a536ba61bbe9c1cc7bea7165 Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Thu, 6 Dec 2018 08:27:49 -0500 Subject: [PATCH] Line endings are now unix. When installing, had to extract for mac and rename to osx --- convert.py | 176 +++++++++++++++++++++++++++-------------------------- 1 file changed, 89 insertions(+), 87 deletions(-) diff --git a/convert.py b/convert.py index afafa34..a1d334e 100644 --- a/convert.py +++ b/convert.py @@ -1,87 +1,89 @@ -import os -import sys -import zipfile -import urllib.request -import tarfile - -inputFolder = 'full-res-files' -outputFolder = 'web-files' -magickHome = "" -dyldLibrary = "" - -def clearScreen(): - os.system('cls' if os.name == 'nt' else 'clear') - -def convertFilesInInput(): - #rename files with spaces - print("Renaming any files in the input folder that have a space and replacing that with a dash.") - for filename in os.listdir(inputFolder): - #os.path.join needed to include path when renaming - os.rename(os.path.join(inputFolder,filename), os.path.join(inputFolder,filename.replace(' ', '-'))) - - for filename in os.listdir(inputFolder): - print("Converting " + filename) - #os.path.splitext(filename)[0] gets rid of file extension if you want a different extension - getProfileCmd = getImagemagickExe() + " " + getInputPath() + filename + " profile.icc" - convertCmd = getImagemagickExe() + " " + getInputPath() + filename + " -resize \"1500x\" -quality 60 -depth 24 -strip -profile \"profile.icc\" " + getOutputPath() + filename - if(os.name == "nt"): - os.system(getProfileCmd) - os.system(convertCmd) - else: - os.system(magickHome + dyldLibrary + getProfileCmd) - os.system(magickHome + dyldLibrary + convertCmd) - os.remove("profile.icc") - -def downloadImagemagick(): - if not os.path.isfile(getImagemagickExe()): - print("ImageMagick does not exist. Downloading now...") - if(os.name == "nt"): - urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-7.0.8-14-portable-Q16-x64.zip", "imagemagick.zip") - zipfile.ZipFile("imagemagick.zip","r").extractall(getImagemagickPath()) - os.remove("imagemagick.zip") - elif(sys.platform == "darwin"): - urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-x86_64-apple-darwin17.7.0.tar.gz", "imagemagick.tar.gz") - tarfile.open("imagemagick.tar.gz","r:gz").extractall(getImagemagickPath()) - os.remove("imagemagick.tar.gz") - else: - print("ImageMagick already downloaded.") - -def getImagemagickPath(): - if(os.name == "nt"): - return "imagemagick\\windows\\" - elif(sys.platform == "darwin"): - return "imagemagick/osx/" - else: - returnErrorAndExit("Your os is not supported. Try using Windows or OSX") - -def getImagemagickExe(): - if(os.name == "nt"): - return getImagemagickPath() + "\\convert.exe" - elif(sys.platform == "darwin"): - currentDir = os.path.dirname(os.path.realpath(__file__)) - global magickHome - magickHome = "export MAGICK_HOME=" + currentDir + getImagemagickPath() + ";" - global dyldLibrary - dyldLibrary = "export DYLD_LIBRARY_PATH=$MAGICK_HOME/lib;" - return getImagemagickPath() + "/bin/convert" - else: - returnErrorAndExit("Your os is not supported. Try using Windows or OSX") - -def getOutputPath(): - if(os.name == "nt"): - return outputFolder + "\\" - else: - return outputFolder + "/" - -def getInputPath(): - if(os.name == "nt"): - return inputFolder + "\\" - else: - return inputFolder + "/" - -def returnErrorAndExit(message): - input(message) - sys.exit() - -downloadImagemagick() -convertFilesInInput() \ No newline at end of file +import os +import sys +import zipfile +import urllib.request +import tarfile + +inputFolder = 'full-res-files' +outputFolder = 'web-files' +magickHome = "" +dyldLibrary = "" + +def clearScreen(): + os.system('cls' if os.name == 'nt' else 'clear') + +def convertFilesInInput(): + #rename files with spaces + print("Renaming any files in the input folder that have a space and replacing that with a dash.") + for filename in os.listdir(inputFolder): + #os.path.join needed to include path when renaming + os.rename(os.path.join(inputFolder,filename), os.path.join(inputFolder,filename.replace(' ', '-'))) + + for filename in os.listdir(inputFolder): + print("Converting " + filename) + #os.path.splitext(filename)[0] gets rid of file extension if you want a different extension + getProfileCmd = getImagemagickExe() + " " + getInputPath() + filename + " profile.icc" + convertCmd = getImagemagickExe() + " " + getInputPath() + filename + " -resize \"1500x\" -quality 60 -depth 24 -strip -profile \"profile.icc\" " + getOutputPath() + filename + if(os.name == "nt"): + os.system(getProfileCmd) + os.system(convertCmd) + else: + os.system(magickHome + dyldLibrary + getProfileCmd) + os.system(magickHome + dyldLibrary + convertCmd) + os.remove("profile.icc") + +def downloadImagemagick(): + if not os.path.isfile(getImagemagickExe()): + print("ImageMagick does not exist. Downloading now...") + if(os.name == "nt"): + urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-7.0.8-14-portable-Q16-x64.zip", "imagemagick.zip") + zipfile.ZipFile("imagemagick.zip","r").extractall(getImagemagickPath()) + os.remove("imagemagick.zip") + elif(sys.platform == "darwin"): + urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-x86_64-apple-darwin17.7.0.tar.gz", "imagemagick.tar.gz") + tarfile.open("imagemagick.tar.gz","r:gz").extractall("imagemagick/") + os.remove("imagemagick.tar.gz") + os.rename("imagemagick/ImageMagick-7.0.8", getImagemagickPath()) + + else: + print("ImageMagick already downloaded.") + +def getImagemagickPath(): + if(os.name == "nt"): + return "imagemagick\\windows\\" + elif(sys.platform == "darwin"): + return "imagemagick/osx/" + else: + returnErrorAndExit("Your os is not supported. Try using Windows or OSX") + +def getImagemagickExe(): + if(os.name == "nt"): + return getImagemagickPath() + "convert.exe" + elif(sys.platform == "darwin"): + currentDir = os.path.dirname(os.path.realpath(__file__)) + global magickHome + magickHome = "export MAGICK_HOME=" + currentDir + "/" + getImagemagickPath() + ";" + global dyldLibrary + dyldLibrary = "export DYLD_LIBRARY_PATH=$MAGICK_HOME/lib;" + return getImagemagickPath() + "bin/convert" + else: + returnErrorAndExit("Your os is not supported. Try using Windows or OSX") + +def getOutputPath(): + if(os.name == "nt"): + return outputFolder + "\\" + else: + return outputFolder + "/" + +def getInputPath(): + if(os.name == "nt"): + return inputFolder + "\\" + else: + return inputFolder + "/" + +def returnErrorAndExit(message): + input(message) + sys.exit() + +downloadImagemagick() +convertFilesInInput()