Fix image optimization pipeline (PR #9257)

This pull request addresses two issues:

  1. The image optimization pipeline tried to optimize jpegs using the operations for png images.

  2. ImageMagick errors were returned to the user, but were not helpful at all.

GitHub

This pull request has been mentioned on Discourse Meta. There might be relevant details there: