1

I'm receiving files from an input via a POST request. I'd like to take to those create a GIF from them and store it directly in a sqlite database.

I have found various ways in python to create GIFs out of images and save them to the file system like the one here

VALID_EXTENSIONS = ('png', 'jpg')

def createGIF(data, duration=0.2):
    images = []
    for d in data:
        images.append(imageio.imread(d))
    output_file = 'Gif-%s.gif' % datetime.datetime.now().strftime('%Y-%M-%d-%H-%M-%S')
    imageio.mimsave(output_file, images, duration=duration)

but I was not able to find a way of creating the GIF and either store it into variable or save it into the DB directly. Is there any way of creating a GIF and not have to save it to disk first before putting it in a DB?

wasp256
  • 5,943
  • 12
  • 72
  • 119

2 Answers2

0

Storing files in a database should never happen. If it’s being considered as a solution for a problem, find a certified database expert and ask for a second opinion.

From: Two Scopes of Django

As coderanger suggested, use a FileField or ImageField instead.

Yannic Hamann
  • 4,655
  • 32
  • 50
-1

For creating GIF's, You can look at this answer: How to create gifs with images in Python.

And for saving it, you will need ImageField.

ranvir
  • 106
  • 1
  • 7
  • I know how to create an GIF in python as my example shows; what I was not able to figure out is how to create a GIF and store it directly in a database (or alternatively store it in a variable) and not having to save it to the file system at all – wasp256 Sep 29 '17 at 20:25
  • You have to save it somewhere. – ranvir Sep 29 '17 at 20:28