Fix StringIO usage when generating thumbnails.