Line endings are now unix. When installing, had to extract for mac and rename to osx

This commit is contained in:
2018-12-06 08:27:49 -05:00
parent 006f5ac204
commit e94e3a6da5

View File

@@ -1,87 +1,89 @@
import os import os
import sys import sys
import zipfile import zipfile
import urllib.request import urllib.request
import tarfile import tarfile
inputFolder = 'full-res-files' inputFolder = 'full-res-files'
outputFolder = 'web-files' outputFolder = 'web-files'
magickHome = "" magickHome = ""
dyldLibrary = "" dyldLibrary = ""
def clearScreen(): def clearScreen():
os.system('cls' if os.name == 'nt' else 'clear') os.system('cls' if os.name == 'nt' else 'clear')
def convertFilesInInput(): def convertFilesInInput():
#rename files with spaces #rename files with spaces
print("Renaming any files in the input folder that have a space and replacing that with a dash.") print("Renaming any files in the input folder that have a space and replacing that with a dash.")
for filename in os.listdir(inputFolder): for filename in os.listdir(inputFolder):
#os.path.join needed to include path when renaming #os.path.join needed to include path when renaming
os.rename(os.path.join(inputFolder,filename), os.path.join(inputFolder,filename.replace(' ', '-'))) os.rename(os.path.join(inputFolder,filename), os.path.join(inputFolder,filename.replace(' ', '-')))
for filename in os.listdir(inputFolder): for filename in os.listdir(inputFolder):
print("Converting " + filename) print("Converting " + filename)
#os.path.splitext(filename)[0] gets rid of file extension if you want a different extension #os.path.splitext(filename)[0] gets rid of file extension if you want a different extension
getProfileCmd = getImagemagickExe() + " " + getInputPath() + filename + " profile.icc" getProfileCmd = getImagemagickExe() + " " + getInputPath() + filename + " profile.icc"
convertCmd = getImagemagickExe() + " " + getInputPath() + filename + " -resize \"1500x\" -quality 60 -depth 24 -strip -profile \"profile.icc\" " + getOutputPath() + filename convertCmd = getImagemagickExe() + " " + getInputPath() + filename + " -resize \"1500x\" -quality 60 -depth 24 -strip -profile \"profile.icc\" " + getOutputPath() + filename
if(os.name == "nt"): if(os.name == "nt"):
os.system(getProfileCmd) os.system(getProfileCmd)
os.system(convertCmd) os.system(convertCmd)
else: else:
os.system(magickHome + dyldLibrary + getProfileCmd) os.system(magickHome + dyldLibrary + getProfileCmd)
os.system(magickHome + dyldLibrary + convertCmd) os.system(magickHome + dyldLibrary + convertCmd)
os.remove("profile.icc") os.remove("profile.icc")
def downloadImagemagick(): def downloadImagemagick():
if not os.path.isfile(getImagemagickExe()): if not os.path.isfile(getImagemagickExe()):
print("ImageMagick does not exist. Downloading now...") print("ImageMagick does not exist. Downloading now...")
if(os.name == "nt"): if(os.name == "nt"):
urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-7.0.8-14-portable-Q16-x64.zip", "imagemagick.zip") 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()) zipfile.ZipFile("imagemagick.zip","r").extractall(getImagemagickPath())
os.remove("imagemagick.zip") os.remove("imagemagick.zip")
elif(sys.platform == "darwin"): elif(sys.platform == "darwin"):
urllib.request.urlretrieve ("https://imagemagick.org/download/binaries/ImageMagick-x86_64-apple-darwin17.7.0.tar.gz", "imagemagick.tar.gz") 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()) tarfile.open("imagemagick.tar.gz","r:gz").extractall("imagemagick/")
os.remove("imagemagick.tar.gz") os.remove("imagemagick.tar.gz")
else: os.rename("imagemagick/ImageMagick-7.0.8", getImagemagickPath())
print("ImageMagick already downloaded.")
else:
def getImagemagickPath(): print("ImageMagick already downloaded.")
if(os.name == "nt"):
return "imagemagick\\windows\\" def getImagemagickPath():
elif(sys.platform == "darwin"): if(os.name == "nt"):
return "imagemagick/osx/" return "imagemagick\\windows\\"
else: elif(sys.platform == "darwin"):
returnErrorAndExit("Your os is not supported. Try using Windows or OSX") return "imagemagick/osx/"
else:
def getImagemagickExe(): returnErrorAndExit("Your os is not supported. Try using Windows or OSX")
if(os.name == "nt"):
return getImagemagickPath() + "\\convert.exe" def getImagemagickExe():
elif(sys.platform == "darwin"): if(os.name == "nt"):
currentDir = os.path.dirname(os.path.realpath(__file__)) return getImagemagickPath() + "convert.exe"
global magickHome elif(sys.platform == "darwin"):
magickHome = "export MAGICK_HOME=" + currentDir + getImagemagickPath() + ";" currentDir = os.path.dirname(os.path.realpath(__file__))
global dyldLibrary global magickHome
dyldLibrary = "export DYLD_LIBRARY_PATH=$MAGICK_HOME/lib;" magickHome = "export MAGICK_HOME=" + currentDir + "/" + getImagemagickPath() + ";"
return getImagemagickPath() + "/bin/convert" global dyldLibrary
else: dyldLibrary = "export DYLD_LIBRARY_PATH=$MAGICK_HOME/lib;"
returnErrorAndExit("Your os is not supported. Try using Windows or OSX") return getImagemagickPath() + "bin/convert"
else:
def getOutputPath(): returnErrorAndExit("Your os is not supported. Try using Windows or OSX")
if(os.name == "nt"):
return outputFolder + "\\" def getOutputPath():
else: if(os.name == "nt"):
return outputFolder + "/" return outputFolder + "\\"
else:
def getInputPath(): return outputFolder + "/"
if(os.name == "nt"):
return inputFolder + "\\" def getInputPath():
else: if(os.name == "nt"):
return inputFolder + "/" return inputFolder + "\\"
else:
def returnErrorAndExit(message): return inputFolder + "/"
input(message)
sys.exit() def returnErrorAndExit(message):
input(message)
downloadImagemagick() sys.exit()
convertFilesInInput()
downloadImagemagick()
convertFilesInInput()