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.models import Tag
from copy import deepcopy
from sorl.thumbnail import get_thumbnail
def addPx(val):
'''
@ -719,17 +720,24 @@ class ImageBox(models.Model):
else:
return self.original_print()
def get_path(self, *args):
if len(args) > 0:
m = args[0]
else:
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 = {
'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)
height = TARGET_WIDTH * aspect_ratio
output_size = (TARGET_WIDTH, int(height),)
context = {'path': filePath, 'size': (100,100,)}
context2 = {'path': filePath, 'size': output_size}
iconPath = get_template("thumbnailTmp.txt").render(Context(context))
resizedPath = get_template("thumbnailTmp.txt").render(Context(context2))
f = open(join(MEDIA_ROOT, filePath))
iconSize = "100x100"
resizedSize = str(TARGET_WIDTH) + "x" + str(int(height))
# 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:
iconPath = "/static/images/binimages/jpg.jpg"
resizedPath = filePath

View File

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