[過去ログ]
Pythonのお勉強 Part74 (1002レス)
Pythonのお勉強 Part74 http://mevius.5ch.net/test/read.cgi/tech/1726881242/
上
下
前
次
1-
新
通常表示
512バイト分割
レス栞
このスレッドは過去ログ倉庫に格納されています。
次スレ検索
歴削→次スレ
栞削→次スレ
過去ログメニュー
341: 警備員[Lv.10][芽] (ワッチョイ 6fad-gDrC) [] 2024/11/17(日) 17:40:21.98 ID:z11Q5dQO0 聞いてみた結果 --from PIL import Image from reportlab.lib.pagesizes import portrait from reportlab.pdfgen import canvas import os # 画像が保存されているディレクトリのパス image_dir = 'my_folder' output_pdf = 'output.pdf' # 画像ファイルのリストを取得し、ファイル名順にソート image_files = sorted([f for f in os.listdir(image_dir) if f.endswith('.jpg')]) # 画像の幅を取得(すべての画像が同じ幅である前提) first_image = Image.open(os.path.join(image_dir, image_files[0])) width, _ = first_image.size # PDFキャンバスの作成 c = canvas.Canvas(output_pdf) # 画像をPDFに追加 for image_file in image_files: image_path = os.path.join(image_dir, image_file) img = Image.open(image_path) img_width, img_height = img.size if img_width != width: raise ValueError(f"Image {image_file} has a different width: {img_width}") # ページサイズを画像の縦サイズに設定し、新しいページを追加 c.setPageSize((width, img_height)) c.showPage() # 画像をPDFに描画 c.drawImage(image_path, 0, 0, width=width, height=img_height) # PDFの保存 c.save() http://mevius.5ch.net/test/read.cgi/tech/1726881242/341
メモ帳
(0/65535文字)
上
下
前
次
1-
新
書
関
写
板
覧
索
設
栞
歴
あと 661 レスあります
スレ情報
赤レス抽出
画像レス抽出
歴の未読スレ
AAサムネイル
Google検索
Wikipedia
ぬこの手
ぬこTOP
0.020s