Do not close image files too early when generating thumbnails...