2

I have a model, lets call it FooModel, that has an image field of type models.Imagefield.

I'm also using wand.image to do some transformation and resizing to an image before I add it to the FooModel.image field.

So I have something along this line:

foo = FooModel()
with Image(file='path/to/image.png') as tmpImage:
  # some transformation on tmpImage
  file_name = 'newTmpFile.png'
  tmpImage.save(filename=file_name)

  f = open(file_name, 'rb')
  foo.image.save('new_file_name.png', File(f), save=True)

So I basically do my transformation, save the image to a temporary place, open it again and pass it to my model's field. This seems extremely redundant and unnecessary, but I haven't managed to pass the tmpImage to the FooModel instance.

I've tried File(tmpImage), just tmpImage, but nothing works. Any other ideas?

Hashirun
  • 89
  • 1
  • 9

0 Answers0