def transform(self, data):
path = self.find_biggest_image(data['props']['srcset'])
name = os.path.basename(path)
image = Image(
caption=data['props'].get('caption', ''),
title=data['props']['alt'] or self.page.title
)
# save temp file
img_temp = NamedTemporaryFile()
img_temp.write(self.get_image_data_from_file(path))
img_temp.flush()
# save file and image
image.file.save(name, File(img_temp), save=True)
image.save()
return {
'type': 'image',
'value': image.id
}
评论列表
文章目录