Add convert to jpg and fix output size calculation.

What it lacks:
* Conversion does not take into account image quality setting.
* Whether or not conversion is performed is judged by the file extension
  (i.e. if source file extension is "jpg" then conversion is skipped).
  This should rely on file's mime-type or at least make it
  case-insensitive.

Ref: #2 #3