1

With version 1.1 I don't understand how I can preprocess the original image (by JUST using imagekit)

https://github.com/jdriscoll/django-imagekit/blob/develop/README.rst

Having a model like this:

class Photo(models.Model):
   original = models.ImageField(etcetera)
   thumbnail = ImageSpec(etcetera)

How do I for instance resize the original image? This was possible in previous imagekits, however the documentation insinuates I need another modelfield?

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
Hedde van der Heide
  • 21,841
  • 13
  • 71
  • 100

3 Answers3

2

You can use ProcessedImageField:

from imagekit.models import ProcessedImageField

class Photo(models.Model):
    original = ProcessedImageField(etcetera)

There is in-code documentation on this class, but it looks like it's not being picked up by readthedocs' autodoc module right now.

I reopened a bug to fix the documentation.

matthewwithanm
  • 3,733
  • 2
  • 21
  • 27
0

Below will do what you are looking for. You can add other processors to the list of processors as well. The processors are run prior to saving the image.

from imagekit.models import ProcessedImageField
from imagekit.processors import ResizeToFit

class Photo(models.Model):
    original = ProcessedImageField(
        upload_to='images/%Y%m',
        format=JPEG,
        processors=[ResizeToFit(200, 100)],
        options={'quality': 90}
    )
Val Neekman
  • 17,692
  • 14
  • 63
  • 66
0

Looking here: https://github.com/jdriscoll/django-imagekit/blob/master/imagekit/processors/resize.py it looks like the Fit class is what you're after.

Untested but I suspect it's something like:

from django.db import models
from imagekit.models import ImageSpec
from imagekit.processors import resize

class Photo(models.Model):
    original_image = models.ImageField(upload_to='photos')
    thumbnail = ImageSpec([resize.Fit(50, 50)], image_field='original_image',
            format='JPEG', options={'quality': 90})
sgallen
  • 2,079
  • 13
  • 10
  • No thats just a processor for the thumbnail.. I want to resize the original image on upload.. this used to be possible with a pre processor in previous django imagekits.. Ofcourse I can use some custom PIL processing, but I'd be surprised if it isn't possible by just using imagekit.. – Hedde van der Heide Jan 20 '12 at 08:57
  • Sorry about that. I understand what you're asking now. Have you tried this: http://stackoverflow.com/questions/2845000/resizing-image-on-upload-with-django-imagekit or is it this methodology that you're saying no longer works? – sgallen Jan 20 '12 at 20:34