I often read some text with images and often happens that the text talks about an image that is on the next page and next page and previous page and I have to go back and forward and usually forget where I paused reading.

I got an idea to save the images to image clipboard which is able to contain about 5 images (e.g. with making small screenshot of the screen area). While reading when the text talks "see picture 10.4 (on page 42)" and in a few seconds "compare it to picture 10.2 (on page 40)" I could press only keyboard shortcut and select the desired picture without browsing through the text.

Is this possible in X Window System? Or with some script?

  • I don't understand how this would work outside the application: only the application knows where it's displayed text and images. What application are you interested in? – Gilles 'SO- stop being evil' May 4 '11 at 20:12
  • If there exist application with this functionality it would be great. – xralf May 5 '11 at 4:56
  • Do you talk about images on webpages (html-format), of PDFs or textprocessing (open office/libre office)? – user unknown May 8 '11 at 22:49
  • When you make a screenshot of the image in pdf or browser it's probably png format. – xralf May 9 '11 at 6:14
  • @xralf: Are you asking about a way to get the screeshots without first actually visiting the pages? ie. Do you want to grab the images only by the text reference? .... Or, on the other hand, do you mean to visit each page to grab each picture, and then go back to reading your main page from where you can access the pre-captured pictures? ... For the first method. see the comments above,.. For the second method. it would be possible, because it only involves basic region-capture and a picture viewer... – Peter.O Aug 7 '11 at 6:15

You may be able to do something with this..
It allows you to collect images (with two mouse clicks per image) in a temp dir, scriptname -c... and then shows the images in a light-weight image viewer which is eaisly navigable via the cursor keys; scriptname -s
It will always start the display with the most recent image. If you really want to limiit it to 5, then you can tweak the script, but they are in /tmp, and that gets cleaned out reasonably often.
Just assign scriptname -c and scriptname -s to shortcut-keys of your choice.. I use xbindkeys to bind my shortcut keys.

# Run $ script  [-c | -s] 
# Uses:  grabc     GRAB Colour - screen pixel colour
#                  Allows you to position amd click the mouse. 
#                  The actual co-ordinates capture is done by xdotool.
#        xdotool   simulate X11 keyboard/mouse input
#        scrot     SCReen shOT - screen capture
#        pnmtopng  (from package 'netpbm') convert format  
#        display   (from package 'imagemagick') display single image  
#        eog        Eye Of Gnome - to display images forward and backwards
# Note: The area selection requires two distinct mouse clicks
#       First click the top-left corner, then the bottom-right corner
#       It is not a click-and-drag style of selection.

bname="$(basename "$0")"
oudir="/tmp/$USER/$bname"; [[ -d "$oudir" ]] || mkdir -p "$oudir"

case "$1" in 
 -s) # show images
     eog "$(find "$oudir" -maxdepth 1 -type f -name 'screen.20[0-9][0-9]-*.png' \
            |sort |tail -n 1)"
  *) # capture image and save to output dir
     grabc 1>/dev/null  2>/dev/null; eval $(xdotool getmouselocation --shell); L=$X; T=$Y
     grabc 1>/dev/null  2>/dev/null; eval $(xdotool getmouselocation --shell); R=$X; B=$Y
     ((R<L||B<T)) && { echo "ERROR: invalid rectangle selected" 1>&2; exit 1; }
     scrot "$oudir/screen.pnm"
     oupic="$oudir/screen.$(date '+%Y-%m-%d %H:%M:%S').png"
          <"$oudir/screen.pnm" pnmcut -left $L -top $T -bottom $B -right $R \
          | pnmtopng > "$oupic"
            display    "$oupic" # for a quick preview.

The original X Window System does only have a X11 selection, which is only text. There are several extensions to implement a clipboard but the applications, which use them are not fully compatible to each other.

Instead of using a X11 clip board you can use Gimp as a clip board. You can start Gimp and after this you can call gimp-remote to load am image for example. You can also try if Gimps paste function is compatible with your application.

Furthermore you can start the Script-Fu server. Default port is 10008. After this you can send Script-Fu commands to the server. For example this creates a new image:

CMD='(gimp-display-new (car (gimp-image-new 300 200 0)))'
echo -e $(printf 'G\\0000\\%0.4o%s' ${#CMD} "$CMD") | nc -q1 localhost 10008

This approach will require some additional programming to implement the functionality you have requested. But is should be possible.


xralf asked:

I got an idea to save the images to image clipboard
Is this possible in X Window System?

The Unix haters handbook says

ICCCM compliance is one of the most complex ordeals of implementing X toolkits, window managers, and even simple applications. It's so difficult, that many of the benefits just aren't worth the hassle of compliance. And when one program doesn't comply, it screws up other programs. This is the reason cut-and-paste never works properly with X (unless you are cutting and pasting straight ASCII text)

Those Unix-haters have a point - I can imagine this sort of thing may have contributed to Apple choosing not to use X-windows in OSX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.