Last active
September 12, 2021 16:40
-
-
Save axpensive/222b0169c13535f8b6f535747a762cd2 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
import glob | |
import os | |
import zipfile | |
import img2pdf | |
from PIL import Image | |
# 電子書籍自炊のためのスクリプト | |
# .cbzをkindleに読み込ませる方法がわからなかったので.pdfに変換 | |
# .cbzより.pdfのほうが画質がいいのでおすすめ | |
def create_pdf(): | |
# convert_cbz_to_zip() | |
# unzip() | |
jpeg_to_pdf() | |
def convert_cbz_to_zip(): | |
files = glob.glob('./*.cbz') | |
for file in files: | |
os.rename(file, file.replace('.cbz', '.zip')) | |
def unzip(): | |
files = glob.glob('./*.zip') | |
for file in files: | |
with zipfile.ZipFile(file) as f: | |
f.extractall('.') | |
def jpeg_to_pdf(): | |
files = os.listdir('.') | |
dirs = [f for f in files if os.path.isdir(os.path.join('.', f))] | |
for dir in dirs: | |
with open(dir + '.pdf', "wb") as f: | |
jpeg_Folder = dir + "/" | |
extension = '.jpeg' | |
jpeg_files = [Image.open(jpeg_Folder + j).filename for j in os.listdir(jpeg_Folder) if j.endswith(extension)] | |
jpeg_files.sort() | |
f.write(img2pdf.convert(jpeg_files)) | |
if __name__ == '__main__': | |
create_pdf() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment