User avatar
addeswe
Posts: 27
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Capture screen of Firefox

Wed May 11, 2016 6:41 am

Hi. So I'm trying to capture the screen of a firefox (this can actually be changed to chrome, libre office whatever).

Is there a library that allows you to do this? (pid-based or whatever) And is it possible also to this while the window is minimized?

With a little luck, somebody has done this before and knows a way to do it!
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

MarcScott
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 81
Joined: Sat Aug 08, 2015 11:30 am

Re: Capture screen of Firefox

Wed May 11, 2016 7:21 am

Are you looking for a way to do this with Python? If so you might like to check out https://pypi.python.org/pypi/pyscreenshot

If not then scrot is a quite popular command line tool for screenshots, although I prefer to use imagemagick - both of which could be called via os.system.

With a minimised window this becomes a little trickier. If it's just the a webpage that you want to capture then you could use phantomJS http://phantomjs.org/ I suppose.

User avatar
addeswe
Posts: 27
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: Capture screen of Firefox

Wed May 11, 2016 8:14 am

Thanks for the reply MarcScott.

At the moment, I'm using pyscreenshot. What I am doing is to capture part of the screen with a bbox. Then reads the r,g,b-values of the pixels. The problem is that sometimes a terminal window gets in the way or I have to swap to another fullscreen application. And then the values are wrong.

So that is why I want to find something that takes a "screengrab" of a pid or a defined window, preferably in minimized state.
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

MarcScott
Raspberry Pi Foundation Employee & Forum Moderator
Raspberry Pi Foundation Employee & Forum Moderator
Posts: 81
Joined: Sat Aug 08, 2015 11:30 am

Re: Capture screen of Firefox

Wed May 11, 2016 11:05 am

I don't know how helpful this will be but:
You can get a window ID and associated PID with

Code: Select all

 wmctrl -lp
You can then use imagemagick to capture the screen, even when it's minimised.

Code: Select all

import -window ID_GOES_HERE output.png
So you should be able to use subprocess to get the results of wmctrl and then pass it all over the wanted id to imagemagick.

I could probably knock some code together later today if you get stuck.

User avatar
addeswe
Posts: 27
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: Capture screen of Firefox

Wed May 11, 2016 1:15 pm

I don't really have any problems with subprocess and I've used it for other projects, but thanks anyways! My only problem with this is that i need to use tmpfs where I save the imagefile if I use it for my project. The software is running checks more then once a second. So that is why I wanted to put the data into the memory instead of memory card. I guess that I'm semi satisfied with the help. Even though, I would be happy if anyone have a better way to do this? :-)
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

stderr
Posts: 2178
Joined: Sat Dec 01, 2012 11:29 pm

Re: Capture screen of Firefox

Wed May 11, 2016 2:51 pm

addeswe wrote: I guess that I'm semi satisfied with the help. Even though, I would be happy if anyone have a better way to do this? :-)
Well, you know, you do get what you pay for. In any case, one option given was phantomjs which certainly can be used to render webpages and save them to a tmpfs. This isn't going to help you with taking pictures of other applications but it is a powerful capability.

User avatar
addeswe
Posts: 27
Joined: Fri Jul 19, 2013 3:49 pm
Location: Sweden

Re: Capture screen of Firefox

Wed May 11, 2016 2:57 pm

My intention was never to sound ungrateful. However phantomjs won't really be the solution to my problem since i read pixeldata. If I offended anyone by saying that "I guess that I'm semi satisfied with the help", I apologize. It was my way of saying that it is a solution but not really the one I would prefer!
“Knock, knock.” - “Who’s there?” - very long pause…. - “Java.”
If a python knocks on your door and says “Hi, I’m a vacuum cleaner!” it’s not true. That’s a python.

Return to “Python”