I am using django image and creating a custom processor. I want to find out the size in KB (or bytes) but unable to do so. The size attribute give the dimensions and not the size of the file. I am a newbie so have only been able to find attr of PIL to get more information about the image but none of the them actually give the file size in bytes.
I have creating this processor for a ModelForm.
Can you please help with this?
I am adding the code written so far. It is more of a test code;
import urllib
import os
class CustomCompress(object):
def process(self, image):
print 'image.width',image.width
print 'image.height',image.height
print 'image.size', image.size
print 'image.info', image.info
print 'image.tobytes', image.tobytes
print 'image.category', image.category
print 'image.readonly', image.readonly
print 'image.getpalette', image.getpalette
st = os.stat(image).st_size
print 'get_size ', st
return image
Here is the forms.py
class PhotoForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(PhotoForm, self).__init__(*args, **kwargs)
self.fields['old_image'] = ProcessedImageField(spec_id='myapp:test_app:old_image',
processors=[CustomCompress()],
format='JPEG',
# options={'quality': 60}
)
class Meta:
model = Photo
fields = ['old_image']