just curious - do you know of any way that will detect if images should probably have been saved in vector format - the detection should be reasonably performant so it isn't wasteful to check before deciding which optimizer to use.
Recent versions of Imagemagick support entropy measurement, which is typically lower in diagram/line art type images. You can check it with 'identify -format "%[entropy]" filename.png'. Some quick testing suggests photographic images usually measure greater than about 0.8.