I want to capture screenshot of a website in high resolution to recognize text or simply to save high quality images. I tried this code in Python 2.7. The website http://www.flaticon.com/ has been taken merely as example.
from selenium import webdriver
import time
driver = webdriver.PhantomJS()
#Setting large window size doesn`t resolve the problem
driver.set_window_size(16000, 12000)
driver.get('http://www.flaticon.com/')
time.sleep(3)
#set resolution 640 dots per inch for this image
#???
driver.save_screenshot('./downloaded/img/welcome_icons.png') # save a screenshot to disk
driver.close()
It captures screenshot, but the resolution is not enough for me. Enlarging window size doesn`t resolve the problem. The picture from webside reside only on the part of the image. It seems that image resolution is not affected. Is there some way to explicitly set image resolution before saving it?
It's a bit hacky, but I solved this problem for myself by increasing the window size width to 3000 and the zoom to 250%.
driver.set_window_size(3000,800)
driver.execute_script("document.body.style.zoom='250%'")
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With