I have a python script recorded with Selenium Builder that takes the full browser screenshot of a webpage using the following:
fileName = "Screenshot1.png"
webDriverInstance.save_screenshot(fileName)
The file size is about 3.5 MB since it is a long, scrollable page and I need the full browser screenshot. I need a way to compress the saved screenshots, or save them as smaller file size PNG images so that I can attach and send several such screenshots in the same email using another Python script (with smtplib).
I tried this:
fileName = "Screenshot1.png"
foo = Image.open(fileName)
fileName2 = "C:\FullPath\CompressedImage.png"
foo.save(fileName2, "PNG", optimize = True)
However, this doesn't seem to be working. Both files, Screenshot1.png and CompressedImage.png are of the same size (about 3.5 MB).
I tried several options with the save method but none of them seem to work. I do not get any errors when I run the script, but there is no decrease in the file size either.
foo.save(fileName2, "PNG", optimize = True, compress_level = 9)
foo.save(fileName2, "PNG", optimize = True, quality = 20)
I am using Python 2.7. Any suggestions?