ImageMagick

ImageMagick is an excellent tool for
transforming images in a multitude of ways. It is powerful and
flexible, although digging into its full potential is not always easy,
often requiring some research to explore how to achieve what you
need. A recent book by Sohail Salehi helps in this regard--see
Section 42.5.