enhance pictures easily
Tuesday, 21 April 2026 08:18 amLast night, instead of going to bed at a sensible time, I wrote a surprisingly simple program in bash script that does something I've wanted for a long time.
There are a few picture enhancing operations I do a lot, and it often feels like overkill to load Gimp to do them. Gimp is wonderful, but it is enormous.
So last night I got the idea to try using one or more of the image suites (ImageMagick, G'MIC, NetPBMtools, or some other) to do what I wanted, or even code my own simple tools.
Very little time was spent actually writing the program. Most was spent doing my favorite thing: learning what would work. In the end, all I needed was ImageMagick to do the enhancements of the images, and feh to display the results.
First a word about feh. When I downloaded it from the respository it had been compiled with auto-updating display turned off, for some strange reason. I recompiled it with auto-updating turned on. That's easy, because it was the default.
So, here is the result -- a tiny program that loads and runs quickly and easily so I can do my alterations without loading in enormous Gimp.
There are a few picture enhancing operations I do a lot, and it often feels like overkill to load Gimp to do them. Gimp is wonderful, but it is enormous.
So last night I got the idea to try using one or more of the image suites (ImageMagick, G'MIC, NetPBMtools, or some other) to do what I wanted, or even code my own simple tools.
Very little time was spent actually writing the program. Most was spent doing my favorite thing: learning what would work. In the end, all I needed was ImageMagick to do the enhancements of the images, and feh to display the results.
First a word about feh. When I downloaded it from the respository it had been compiled with auto-updating display turned off, for some strange reason. I recompiled it with auto-updating turned on. That's easy, because it was the default.
So, here is the result -- a tiny program that loads and runs quickly and easily so I can do my alterations without loading in enormous Gimp.
#! /bin/bash
# image_fix
# by Miriam
# Monday 2026-04-20 07:55:54 pm
#
# Enhances an image using auto or manual levels
# gamma curve or S-curve to the image's shades.
# And displays a histogram as a guide.
# Uses feh to display the image and the histogram
# because feh can auto-update its display when the image changes
#
# function to make the histogram image of the current picture
function hist {
magick "$tempfile" -colorspace Gray -define histogram:unique-colors=false histogram:/tmp/hist.png
}
# copy the image to /tmp and work on that
# so if I make a mistake I can revert to the original
tempfile="/tmp/img_fix_$1"
cp "$1" "$tempfile"
feh "$tempfile" &
MSGPID1=$!
# display the histogram too
hist
feh /tmp/hist.png &
MSGPID2=$!
# make the menu one column
COLUMNS=1
# set up the menu with highlighted first letters
select menu in $'\e[46ma\e[0muto-level' $'\e[46ml\e[0mevel values (black level, white level)' $'\e[46mg\e[0mamma curve (>1 lightens, <1 darkens)' $'\e[46mS\e[0m-curve (contrast x midpoint)' $'\e[46mm\e[0modulate (brightness, saturation)' $'\e[46mu\e[0mndo' $'\e[46mw\e[0mrite back to original image' $'e\e[46mx\e[0mit'
# loop forever
do
if [ "$REPLY" = "1" -o "$REPLY" = "a" ] ;then
echo "auto-level"
magick mogrify -auto-level "$tempfile"
hist
fi
if [ "$REPLY" = "2" -o "$REPLY" = "l" ] ;then
echo "level values"
read -p "Black level % " black
read -p "White level % " white
magick mogrify -level "${black}%,${white}%" "$tempfile"
hist
fi
if [ "$REPLY" = "3" -o "$REPLY" = "g" ] ;then
echo "gamma"
read -p "Gamma value (>1 lightens, <1 darkens) " gamma
magick mogrify -colorspace RGB -gamma "$gamma" -colorspace sRGB "$tempfile"
hist
fi
if [ "$REPLY" = "4" -o "$REPLY" = "s" ] ;then
echo "s-curve"
read -p "Contrast (0 is none; 3 is typical; 20 is a lot) " contrast
read -p "Midpoint (0 is white; 50 is gray; 100 is black) " midpoint
magick mogrify -colorspace RGB -sigmoidal-contrast "${con}x${mid}%" -colorspace sRGB "$tempfile"
hist
fi
if [ "$REPLY" = "5" -o "$REPLY" = "m" ] ;then
echo "modulate brightness and saturation"
read -p "brightness (50 is half, 100 unchanged, 200 twice) " bright
read -p "Saturation (0 grayscale, 100 unchanged, 200 oversaturated " saturation
magick mogrify -modulate "$brightness,$saturation" "$tempfile"
hist
fi
if [ "$REPLY" = "6" -o "$REPLY" = "u" ] ;then echo "undo"; cp "$1" "$tempfile" ; hist; fi
if [ "$REPLY" = "7" -o "$REPLY" = "write" ] ;then echo "write"; cp "$tempfile" "$1" ; hist; fi
if [ "$REPLY" = "8" -o "$REPLY" = "x" ] ;then echo "exit"; break ; fi
done
# clean up temporary files
rm "$tempfile"
if [ -e /tmp/hist.png ] ; then rm /tmp/hist.png ; fi
# and kill the histogram view
kill $MSGPID1
kill $MSGPID2