Created
June 29, 2017 13:22
-
-
Save DominicBM/4e5e4ca748842d322e6cb118a01cfb23 to your computer and use it in GitHub Desktop.
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
# This script requires Wand for Python. Install using the documentation at http://docs.wand-py.org/en/0.4.1/index.html before running. | |
import sys, os, datetime | |
from wand.image import Image | |
list = os.listdir(os.getcwd()) | |
tuples = [] | |
for file in list: | |
location = os.path.join(os.getcwd(), file) | |
size = os.path.getsize(location) | |
tuples.append((file, size)) | |
tuples.sort(key=lambda s: s[1]) | |
for n in tuples: | |
item = n[0] | |
if item.endswith(".pdf"): | |
start = datetime.datetime.now() | |
print 'Working on "' + item + '" (' + str(datetime.datetime.now()) + ').' | |
with Image(filename=item, resolution=300) as readpdf: | |
pages = len(readpdf.sequence) | |
folder = os.getcwd() + '/' + item[:-4] | |
if not os.path.exists(folder): | |
os.makedirs(folder) | |
jpgfile = folder + '/' + item[:-4] + '.jpg' | |
readpdf.compression_quality = 100 | |
readpdf.compression = 'no' | |
readpdf.COLORSPACE_TYPES = 'srgb' | |
readpdf.save(filename=jpgfile) | |
os.rename(item, folder + '/' + item) | |
end = datetime.datetime.now() | |
print 'Took ' + str(int(round((end - start).total_seconds()))) + ' seconds for "' + item + '" (' + str(pages) + ' page(s)).' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment