Added Thumbnail.rewrite with quality control