{"id":26596,"date":"2022-04-08T23:30:19","date_gmt":"2022-04-08T18:00:19","guid":{"rendered":"https:\/\/python-programs.com\/?p=26596"},"modified":"2022-04-08T23:30:19","modified_gmt":"2022-04-08T18:00:19","slug":"how-to-take-screenshots-of-particular-size-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-take-screenshots-of-particular-size-in-python\/","title":{"rendered":"How to Take Screenshots of Particular Size in Python?"},"content":{"rendered":"
In this article, let us\u00a0see how to use Python to capture a specific portion of a screen. In many circumstances, we need to take a screenshot<\/strong> of a specific portion of the application.<\/p>\n Below are the ways to Take Screenshots of Particular Size in Python:<\/p>\n Before we work with this pyscreenshot module we use should first install pillow (PIL) on our system as shown below.<\/p>\n Installation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n <\/p>\n <\/p>\n <\/p>\n","protected":false},"excerpt":{"rendered":" In this article, let us\u00a0see how to use Python to capture a specific portion of a screen. In many circumstances, we need to take a screenshot of a specific portion of the application. Taking Screenshots of Particular Size in Python Below are the ways to Take Screenshots of Particular Size in Python: Using pyscreenshot Module …<\/p>\nTaking Screenshots of Particular Size in Python<\/h2>\n
\n
Method #1: Using pyscreenshot Module<\/h3>\n
pip install pillow<\/pre>\n
pip install pyscreenshot<\/pre>\n<\/div>\n
Collecting pyscreenshot\r\nDownloading pyscreenshot-3.0-py3-none-any.whl (27 kB)\r\nCollecting jeepney\r\nDownloading jeepney-0.7.1-py3-none-any.whl (54 kB)\r\n|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 54 kB 1.9 MB\/s \r\nCollecting EasyProcess\r\nDownloading EasyProcess-1.1-py3-none-any.whl (8.7 kB)\r\nCollecting mss\r\nDownloading mss-6.1.0-py3-none-any.whl (76 kB)\r\n|\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 76 kB 4.0 MB\/s \r\nCollecting entrypoint2\r\nDownloading entrypoint2-1.0-py3-none-any.whl (9.8 kB)\r\nInstalling collected packages: mss, jeepney, entrypoint2, EasyProcess, pyscreenshot\r\nSuccessfully installed EasyProcess-1.1 entrypoint2-1.0 jeepney-0.7.1 mss-6.1.0 \r\npyscreenshot-3.0<\/pre>\n
\n
# Import pyscreenshot module using the import keyword\r\nimport pyscreenshot\r\n# Pass the dimensions of the screen in pixels to the bbox() function and \r\n# pass it as an argument to the grab() to capture the screenshot of the given size.\r\n# Store it in a variable.\r\nscreenshot = pyscreenshot.grab(bbox=(100, 200, 450, 350))\r\n# Display the screenshot using the show() function\r\nscreenshot.show()\r\n# Save the screenshot with some random name in .png format using the save() function\r\nscreenshot.save(\"sample_screenshot.png\")<\/pre>\n
Method #2: Using pillow Module<\/h3>\n
\n
# Import ImageGrab from PIL(pillow) module using the import keyword\r\nfrom PIL import ImageGrab\r\n# Pass the dimensions of the screen in pixels to the bbox() function and \r\n# pass it as an argument to the grab() function of the ImageGrab to capture the \r\n# screenshot of the given size.\r\n# Store it in a variable.\r\nscreenshot = ImageGrab.grab(bbox=(90, 120, 450, 350))\r\n# Display the screenshot using the show() function\r\nscreenshot.show()\r\n# Save the screenshot with some random name in .png format using the save() function\r\nscreenshot.save(\"output_screenshot.png\")<\/pre>\n