Import using 100% CPU

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Justin Hendrickson

Import using 100% CPU

Post by Justin Hendrickson »

I want to use import to take regular pictures of my desktop, so I setup a bash script to sleep 10 minutes, then use import and repeat.

Code: Select all

#!/bin/bash
while true; do
    directory=/home/jhendric/screenshots/`date +%b%d`

    if [ ! -e "$directory" ]; then
        mkdir $directory
    fi

    import -window root -silent $directory/`date +%H%M`.gif

    sleep 10m
done
The only issue is that import uses 100% CPU every time it runs, so X locks up for 3-5 seconds while import runs. I tried using nice, but it didn't help any.

I know it's a bit of an off-topic question, but I thought I'd ask since it'd be helpful for me.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Import using 100% CPU

Post by magick »

Add -screen to your command line, that may help. Otherwise, the delay is expected. The X server is locked so the pixels do not change while a snapshot is taken.
Justin Hendrickson

Re: Import using 100% CPU

Post by Justin Hendrickson »

I found an alternative to import, called xwd (http://en.wikipedia.org/wiki/Xwd), that doesn't cause a 100% CPU spike while running. Here's the script, for anyone that cares.

Code: Select all

#!/bin/bash
while true; do
    directory=/home/jhendric/screenshots/`date +%b%d`

    if [ ! -e "$directory" ]; then
        mkdir $directory
    fi

    xwd -root | convert - $directory/`date +%H%M`.png

    sleep 10m
done
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Import using 100% CPU

Post by anthony »

There is also a lower level standard X window utility called "xwd" to take snapshots. however its out put is the 'xwd' format but IM understands this so that is no drama.

Code: Select all

xwd -root | convert - snapshot.png
By default it 'beeps' once at the start and twice at the end, which can get annoying, so adding -silent to the options is a good idea too.

PS; the default xwd converter is xwud

Code: Select all

xwd -root | xwud
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply