Page 1 of 1

Capturing multiple images from one "import" invocation

Posted: 2009-06-22T07:25:18-07:00
by victorlesk
Hi - I want to capture different parts of the screen simultaneously and store them to different files. Is there any way of doing this using just one invocation of "import"?

e.g. along the lines of
import -window root -crop 100x100+100+100 a.pnm 300x200+120+30 b.pnm

etc. (although the above doesn't work of course).

The reason I want to do this is because "import" command seems to take several seconds and this being a time critical application I would prefer to call it just once!

Thanks -victor

Re: Capturing multiple images from one "import" invocation

Posted: 2009-06-23T20:03:21-07:00
by anthony
Rather than use import, you can just read the screen using x: from convert

Code: Select all

  convert x:root'[100x100+50+50]'  +repage -write dump1.png +delete \
               x:root'[100x100+200+200]'  +repage -write dump2.png +delete \
               x:root'[100x100+600+50]'  +repage dump3.png
This reads one image from the display, writes it then deletes it from memory, then repeats it with another image from a different area. Of course the final option is an automatic -write, and as the command ends does not need to
be deleted.

But if you want to keep things simple you can still do it the same way just just junk the final write

Code: Select all

  convert x:root'[100x100+50+50]' +repage  -write dump1.png +delete \
               x:root'[100x100+200+200]'  +repage -write dump2.png +delete \
               x:root'[100x100+600+50]'  +repage -write dump3.png +delete \
               null:
The [...] is actually a read modifier and is equivelent to a -crop so a single read of the root window may be better.

Code: Select all

  convert x:root  \
               \( +clone -crop 100x100+50+50  +repage  -write dump1.png +delete \) \
               \( +clone -crop 100x100+200+200 +repage -write dump2.png +delete \) \
               \( +clone -crop 100x100+600+50  +repage -write dump3.png +delete \) \
               null:
You can also ask for a specifc window,using the X window ID (which you can get from the "xwininfo" command), or a terminal WINDOWID environment variable, you can use it.

Code: Select all

convert x:$WINDOWID  this_terminal.png
I have updated the special file types for "X" in IM Examples
http://www.imagemagick.org/Usage/files/#x
With the above information (and more).


NOTE that the "display" program can even 'draw' an image into a another applications X window..

From an 'xterm' try this...

Code: Select all

  window=`xwininfo -children -id $WINDOWID |\
                  sed -n 's/^ *\(0x[^ ]*\).*/\1/p'`; \
  convert x:$window -background black \
          -draw 'fill black         rectangle 40,40 160,160' \
          -draw 'stroke red         line 50,50 50,150 line 50,150 150,150' \
          -draw 'fill lime          circle 110,100 80,100' \
          -draw 'stroke dodgerblue  line 50,150 150,50' \
          png:- |\
    display -window $window -
The funny bit at the top is because the window to draw into must be the 'child' window of the one given as $WINDOWID. For a Gnome-Terminal, you can just directly assign "window=$WINDOWID".

NOTE the XTERM application does not know of the changes you made to its window. How could it! As such if the window is re-drawn for some reason (remove an obscuring window, change desktop, iconize/de-iconize, scrolls off then on again) then the xterm application will redraw what it things should be present, so destroying the effect.

That is it is temporary!

Now imagine what you can do with this!!!!

Re: Capturing multiple images from one "import" invocation

Posted: 2009-06-24T00:55:29-07:00
by victorlesk
omg thanks!