0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

jpgからpngへの変換

Last updated at Posted at 2024-02-02

フォルダ内のjpegをpngに変換する

from google.colab import drive
drive.mount('/content/drive')

from PIL import Image
import os

def convert_jpg_to_png(input_folder, output_folder):
    # 1. 入力フォルダ内のJPEG画像をリストアップ
    jpg_files = [f for f in os.listdir(input_folder) if f.endswith('.jpg')]

    # 2. 出力フォルダが存在しなければ作成
    os.makedirs(output_folder, exist_ok=True)

    # 3. 各JPEG画像をPNGに変換
    for jpg_file in jpg_files:
        jpg_path = os.path.join(input_folder, jpg_file)
        # PNGの出力パスを生成
        png_path = os.path.join(output_folder, os.path.splitext(jpg_file)[0] + '.png')

        # 画像の変換
        img = Image.open(jpg_path)
        img.save(png_path, 'PNG')

if __name__ == "__main__":
    input_folder = "path"  # JPEG画像があるフォルダ
    output_folder = "path"  # PNG画像を保存するフォルダ

    convert_jpg_to_png(input_folder, output_folder)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?