updated code for updated sorl + fixed PNG support

This commit is contained in:
Sanj 2011-06-19 14:12:12 +05:30
parent 5cdf8cb75d
commit cbaa2b8400
4 changed files with 29 additions and 10 deletions

View File

@ -14,6 +14,7 @@ from django.contrib.auth.models import User, Group
from tagging.fields import TagField from tagging.fields import TagField
from tagging.models import Tag from tagging.models import Tag
from copy import deepcopy from copy import deepcopy
from sorl.thumbnail import get_thumbnail
def addPx(val): def addPx(val):
''' '''
@ -719,17 +720,24 @@ class ImageBox(models.Model):
else: else:
return self.original_print() return self.original_print()
def get_path(self, *args): def get_path(self, *args):
if len(args) > 0: if len(args) > 0:
m = args[0] m = args[0]
else: else:
m = 1 m = 1
path = self.actual_unresized() path = join(MEDIA_ROOT, self.actual_unresized())
f = open(path)
size = str(self.width * m) + "x" + str(self.height * m)
im = get_thumbnail(f, size, crop='center', quality=99)
'''
context = { context = {
'path': path, 'path': path,
'size': (self.width * m, self.height * m,) # 'size': (self.width * m, self.height * m,)
'size': str(self.width * m) + "x" + str(self.height * m)
} }
return get_template("thumbnailTmp.txt").render(Context(context)) '''
return im.url

View File

@ -407,10 +407,13 @@ def category_json(request):
aspect_ratio = orig_size[1] / (orig_size[0] + .0) aspect_ratio = orig_size[1] / (orig_size[0] + .0)
height = TARGET_WIDTH * aspect_ratio height = TARGET_WIDTH * aspect_ratio
output_size = (TARGET_WIDTH, int(height),) output_size = (TARGET_WIDTH, int(height),)
context = {'path': filePath, 'size': (100,100,)} f = open(join(MEDIA_ROOT, filePath))
context2 = {'path': filePath, 'size': output_size} iconSize = "100x100"
iconPath = get_template("thumbnailTmp.txt").render(Context(context)) resizedSize = str(TARGET_WIDTH) + "x" + str(int(height))
resizedPath = get_template("thumbnailTmp.txt").render(Context(context2)) # context = {'path': filePath, 'size': (100,100,)}
# context2 = {'path': filePath, 'size': output_size}
iconPath = get_thumbnail(f, iconSize, crop="center", quality=99).url
resizedPath = get_thumbnail(f, resizedSize, quality=99).url
except: except:
iconPath = "/static/images/binimages/jpg.jpg" iconPath = "/static/images/binimages/jpg.jpg"
resizedPath = filePath resizedPath = filePath

View File

@ -55,12 +55,14 @@ def convertFile(**kwargs):
fname = str(f.file) fname = str(f.file)
ext = e.models.extFileName(fname) ext = e.models.extFileName(fname)
f.ext = ext f.ext = ext
if f.ext in ['jpg', 'JPG']: if f.ext in ['jpg', 'JPG', 'jpeg', 'JPEG', 'png', 'PNG']:
f.type = 'image' f.type = 'image'
elif f.ext in ['ogg', 'oga']: elif f.ext in ['ogg', 'oga']:
f.type = 'audio' f.type = 'audio'
elif f.ext in ['ogv']: elif f.ext in ['ogv']:
f.type = 'video' f.type = 'video'
elif f.ext in ['doc', 'pdf', 'rtf', 'txt']:
f.type = 'text'
else: else:
f.type = 'other' f.type = 'other'
f.save() f.save()

View File

@ -1,3 +1,9 @@
{% load thumbnail %}
{% thumbnail path size crop %}
{% load thumbnail %}
{% thumbnail path size crop="center" as im %}
{{ im.url }}
{% empty %}
no image
{% endthumbnail %}
path:{{ path }} size:{{ size }}