It can be easily implemented as a filter[1][2]. If you need to use it via command-line you can save the current buffer as a tempfile[3], call your CLI with the tempfile path and read the tempfile to use as the new buffer.
It's even simpler if your CLI can take a stdin argument, since you can just pass the buffer as a stdin parameter.
Thumbor's filter infrastructure allows you to change the image incrementally.