If you're using Gimp RobA wrote a script for just that: https://www.cartographersguild.com/s...ead.php?t=6465

There may be an equivalent Photoshop plugin somewhere.