ImageMagick + Gimp + PNG Offset Trouble

August 5th, 2007

I have a custom little utility that I wrote that uses ImageMagick and Zenity to take a screen shot. I have the script hooked up to Z keyboard command. This is the bash script.

#!/bin/bash

fn=$(zenity --entry --title='File Name' --text='File Name Prefix');
dt=`date '+%Y%m%d'`;
screenshot="/home/USERNAME/Desktop/$fn-$dt.png";
import -frame +repage $screenshot;

Be sure to change USERNAME to your actual username so the path to your desktop will be correct. Also, for the sake of your sanity, please note the +repage switch that we pass to ImageMagick’s import command. Without that, Gimp will be very unhappy with the offset of the PNG. The layer will appear outside of the image and you won’t be able to see your screen shot in Gimp. If you happen to have that problem already, you can zoom out in Gimp, then use the move tool to drag your image back into view.

The screen shot utility, when invoked, will first prompt you for a little file name prefix using zenity. That prefix will have a date appended to the end of the saved file name. So, for example, if you ran this script today and typed in “receipt” as the file name prefix, the final saved image will be named “receipt-20070804.png” since today is August 4th, 2007. After typing in your file name prefix, you will see a + style cursor. Either click on a window or click and drag a selection on your screen to take the screen shot. The sreen shot will be saved to your desktop.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

3 Responses to “ImageMagick + Gimp + PNG Offset Trouble”

  1. Raleigh Cross Says:

    Thanks, the +repage tip saved me from frustration when I was ripping game sprites from a sprite sheet.

  2. mf Says:

    Yeah, that +repage thing is a lifesaver! Gimp has been driving me nuts with the messed up PNG offset — really nice to find a fix for that. And nice to be introduced to zenity, too! I’ve been wondering what it was for, but never looked into it. Now I know!

  3. Ricardo Fabbri Says:

    Thanks for putting this up. +repage to remove the offsets in the PNG is the tiny gem I needed!

Leave a Reply