https://automatetheboringstuff.com/chapter17/
>>> from PIL import Image
>>> import os
>>> os.chdir('c:\\temp\\pythonwork_01')
>>> catIm = Image.open('zophie.png')
>>> catIm.size (816, 1088)
>>> width, height = catIm.size
>>> width 816
>>> height 1088
>>> catIm.filename 'zophie.png'
>>> catIm.format 'PNG'
>>> catIm.format_description 'Portable network graphics'
>>> catIm.save('copy.jpg')
最後にsaveでjpgで保存している。オリジナルファイルの形式はpngだったがImageパッケージを利用するとファイル拡張子の変換も自動的に実施できる。
https://automatetheboringstuff.com/chapter18/
ようやくautomated the boringも最終チャプターまできた。このチャプターではマウスとキーボード操作について取り扱う。
まずはマウスからである。スクリプトを実行するとマウスは勝手に動く。正確にはスクリプトで指示されたとおりに動く
>>> import pyautogui >>> pyautogui.size() (1366, 768) >>> width, height = pyautogui.size() >>> for i in range(10): ... pyautogui.moveTo(100,100, duration=0.25) ... pyautogui.moveTo(200,100, duration=0.25) ... pyautogui.moveTo(200,200, duration=0.25) ... pyautogui.moveTo(100,200, duration=0.25)
とりあえずautomated the boringについてはここまでにしておく。pythonについて完全な初心者だととっつきずらい。ある程度文法が理解できているならばアプリケーションを作るための処理がコンパクトにまとまっているし、利用範囲がひろいパッケージが取り上げられているのでおすすめである。