django-imagekit
django-imagekit copied to clipboard
Cache or thread problem
I have this view:
from os import path, makedirs
import imghdr
from django.http import HttpResponse, Http404
from django.conf import settings
from imagekit import ImageSpec
from imagekit.processors import ResizeToFit
class Thumbnail(ImageSpec):
processors = []
format = 'JPEG'
options = {'quality': 71}
def __init__(self, **kwargs):
self.processors.append(ResizeToFit(width = kwargs['width'],
height = kwargs['height'],
upscale = False)
)
return super(Thumbnail, self).__init__(source = kwargs['source'])
def customizepic(request, *args, **kwargs):
'''
resize image to size defined in url like
cp/(?P<params>.+?)/(?P<img_path>.*)
'''
customized_img = path.join(settings.CP_ROOT, kwargs['params'] , kwargs['img'])
#image exist and nginx should serve this url, but for development server
if path.isfile(customized_img):
return HttpResponse(open(customized_img,'rb'), content_type="image/jpeg")
original_img = path.join(settings.MEDIA_ROOT, kwargs['img'] )
if path.isfile(original_img) and imghdr.what(original_img) == 'jpeg':
width, height = kwargs['params'].split('h')
width = int(width[1:])
height = int(height)
if not width or not height:
raise Http404
source = open(original_img,'rb')
print height
image_generator = Thumbnail(source = source, height = height, width = width)
if not path.isdir(path.split(customized_img)[0]):
makedirs(path.split(customized_img)[0])
with open(customized_img, 'wb') as w:
w.write(image_generator.generate().read())
with open(customized_img, 'rb') as f:
return HttpResponse(f, content_type="image/jpeg")
raise Http404
So, i run django development server and request page which contains two different sizes of one image. Theirs url /cp/w100h100/media/sdsds.jpg and /cp/w200h200/media/sdsds.jpg. Everything works fine, but both generated thumbnail has 200x200 size, like the last requested.
Is it cache problem? How i can disable it at all?
Would you explain the problem and how it can be reproduced?
Sorry. I pressed submit button accidentally. i've corrected issue
If you are trying to set dummy cache if the problem still persist?
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}
@Nabu-thinker-ru can you check what I asked for in the comment above?
Without more information I'm unable to help