Drkcore

12 01 2010 Python PIL Tweet

pythonで画像のリサイズ

PILを使うと簡単にかける

Image.open(f).resize((480,360)).save(outfile)

と書くだけで読み込んでリサイズして別名で保存できる。そんな感じで、とりあえずflickrのかわりに、リサイズして保存したらmarkdown書式でURLを出力するようなスクリプトを書いた。

import sys,datetime
import Image

if len(sys.argv) < 2:
  print sys.argv[0], " image_file"

for f in sys.argv[1:]:
  now = datetime.datetime.now().strftime('%s')
  outfile =  "/var/www/html/images/blog/" + now + ".jpg"
  Image.open(f).resize((480,360)).save(outfile)
  print r"![%s](http://www.kzfmix.com/images/blog/%s)" % (now,now + ".jpg")

1203853093

あとはドラッグドロップで転送するようにする

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021