Skip to content

Instantly share code, notes, and snippets.

@JedBeom
Created August 15, 2021 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JedBeom/a00df7e1e5c432fe0bea4da2e7defb3d to your computer and use it in GitHub Desktop.
Save JedBeom/a00df7e1e5c432fe0bea4da2e7defb3d to your computer and use it in GitHub Desktop.
'''
참고:
requests: https://stackoverflow.com/questions/13137817/how-to-download-image-using-requests
FPDF: https://stackoverflow.com/questions/27327513/create-pdf-from-a-list-of-images
'''
import requests
import shutil
from fpdf import FPDF
IMAGE_MAX = 192 # edit
def get_link(no: int) -> str:
return f"https://path/to/{no}.jpg"
for i in range(1, IMAGE_MAX+1):
print(f"{i}/192")
r = requests.get(get_link(i), stream=True)
if r.status_code != 200:
print("ERROR!", r.status_code)
break
with open(f"{i}.jpg", "wb") as f:
shutil.copyfileobj(r.raw, f)
del r
pdf = FPDF()
for image in [f"{i}.jpg" for i in range(1, IMAGE_MAX+1)]:
pdf.add_page()
pdf.image(image, 0, 0, 210, 270) # edit
pdf.output("PDFFILENAME.pdf", "F") # edit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment