LoginSignup
2
1

More than 1 year has passed since last update.

pythonでpng画像をjpg画像に変換するスクリプト

Posted at

動機

pythonスクリプトで画像表示ができるようになったので、その次のステップとして画像の形式の変換、PNG画像からJPG画像への変換を行ってみる。PIL(Pillow)を使うと簡単にできた。以下そのスクリプト

png2jpg.py
#!/usr/bin/env python3

import sys
from PIL import Image

if __name__ == '__main__':
    if sys.argv[1].endswith(".png"):
        img = Image.open(sys.argv[1])
        newImg = img.convert("RGB") # パレットモードのままJPG形式には変換できないようなのでRGBモードにコンバートする。
        newImg.save(sys.argv[1][0:-3]+"jpg")

課題

  • PILを使わずmatplotlibを使ってnumpyのアレイ形式を変換してできないものだろうか。
  • FFTを使ってJPG形式へ自作スクリプトで変換できるようになりたい。
2
1
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
2
1