#環境
・Mac Catalina
・Python 3.8.1
#Macでの設定
そのままだと、スクリーンショットをとってもデスクトップがとられてしまうため、
画面収録の許可を行います。
『システム環境設定』→『セキュリティとプライバシー』
![システム環境設定.jpg](https://qiita-user-contents.imgix.net/https%3A%2F%2Fqiita-image-store.s3.ap-northeast-1.amazonaws.com%2F0%2F431502%2Fb732151b-6dd4-5bbe-15ea-e195e134d644.jpeg?ixlib=rb-4.0.0&auto=format&gif-q=60&q=75&s=c554cb235796fbabb9f220fddbaf8419)
『画面収録』にターミナルにチェックを入れる。
#スクリーンショットをとる
pyautoguiをインストールします。
pip install pyautogui
pyautogui.screenshot()で全画面のスクリーンショットをとれます。
import pyautogui
screenshot = pyautogui.screenshot()
screenshot.save('スクリーンショット.png')
#範囲を指定する場合
region = (左からの配置位置, 上からの配置位置, 幅, 高さ)を使用することで、
特定範囲のスクリーンショットをとれます。
import pyautogui
screenshot = pyautogui.screenshot(region = (100, 200, 1500, 875))
screenshot.save('スクリーンショット.png')
#JPEGで保存する場合
RGBに変換することで、 JPEGで保存することができます。
screenshot = screenshot.convert('RGB')