gregmuellegger/django-autofixture

Support for imagefield

Closed this issue · 7 comments

As I understood from autofixture / base.py there is no support for this.
It would be nice to have support for imagefields. The obvious problem is what images should be used? Well place a kitten is a start: http://placekitten.com/ or something like this http://placehold.it/

so the process of auto filling imagefield is not that hard:

  1. download random set of images with random resolutions
  2. fill the fields with random files

Possible problems:

  1. where to put the images? Media folder? actually imagefield has to have the upload attribute so here we go.

Any thoughts?

Support for image fields would be awesome! Some thoughts on this:

The images could be generated by Pillow. I think using a webservice for this isn't a good choice since this would break your setup if you are offline.
Hm the storing problem is propably not that easy since you don't want to pollute the filesystem too much. So I think ImageFields should only be filled by autofixture if you opt-in by passing a flag. Those images should then go maybe into MEDIA_ROOT/_autofixture/images/ or so. So that you can easily identify the ones that were created by autofixture.

I'm open for any ideas. And a pull request if you get that far ;)

I agree with the offline argument. A quick google revealed python generators of https://github.com/emidln/python-placeholder, https://github.com/samhain13/image-placeholder-server/blob/master/imgphserv.py the first one is awkwardly packaged but it worked for me. The packaging problem can be easily solved by forking.

I want this feature so I will probably fork, but at the moment I have no time to study style of this library, (though it seem that it should be only about adding generator and some test.)

Filesystem pollution problem could be solved with storing only distinct images. Image generator function could calculate hash value based on passed arguments, and search image that corresponds to that hash on filesystem.

We dont need to calculate the hash, we already know that specs of the file generated so it would be enough to generate only about five images and use them repeatedly.

I meant - if user will want to generate 1000 images with 500x500 dimensions, blue background and text string in foreground - generator could calculate a hash from that parameters "500x500 blue sometext", and write just one file, using hash as filename. And later if user will want generate another 1000 of objects with images with the same paremeters, generator will calculate hash value, find existing file with filename equals to that hash, and reuse it.

I have created this for generating placeholder images: https://github.com/Visgean/python-placeholder

I have created pull request so I guess the discussion can move there