Fix a bug: sort image before generating package