Last active
May 6, 2024 01:18
-
-
Save robinfang/e0b6fe57fe2db66537c36ce504e17ed2 to your computer and use it in GitHub Desktop.
pdf提取页面为jpg图片
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 glob | |
import argparse | |
from wand.image import Image | |
import pdb | |
def convert2jpg(diag, pg=None): | |
with(Image(filename=diag,resolution=200)) as source: | |
images=source.sequence | |
pages=len(images) | |
if pg is not None: | |
pages=pg | |
for i in range(pages): | |
Image(images[i]).save(filename="{}_{}.jpg".format(diag,i)) | |
if __name__ == '__main__': | |
parser = argparse.ArgumentParser() | |
parser.add_argument('file', help='Input file paths') | |
parser.add_argument('--pages', type=int, help='获取前多少页') | |
args = parser.parse_args() | |
pg = args.pages | |
file_list = list(glob.iglob(args.file)) | |
print("to convert: {}".format((",").join(file_list))) | |
# pdb.set_trace() | |
for file_name in file_list: | |
convert2jpg(file_name, pg) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment