There are major speed benefits to image optimization using optipng for PNGs, gifsicle for GIFs, and jpegoptim for JPEGs. Optimized graphics transfer faster and improve perceived load times. Below, optipng and gifsicle optimize PNG/GIF files losslessly, whereas adding --max=85 or ImageMagick -quality 80 applies bounded lossy compression to JPEGs (omit --max=85 if you only want lossless metadata stripping).
Run these commands inside the target directory as the user who owns those images (note the quoted '*.ext' globs so the shell never expands them prematurely):