Example #1
0
def get_story_image(request, story, size=None):
    try:
        story = ArticleStory.objects.select_related().get(pk=story)
        allowed_objects = get_allowed_objects(
            request.user, ArticleCategory, 'reader')
        al = story.categories.filter(pk__in=allowed_objects)
        if len(al) == 0:
            return HttpResponseRedirect('/')
    except:
        return HttpResponseRedirect('/')

    path = u"%s/%s" % (get_upload_articles_images(), story.image)
    if size:
        miniature = resize_image(story.image.path, size)
        split = path.rsplit('/', 1)
        path = '%s/%s' % (split[0], miniature)

    try:
        image_data = open(path, "rb").read()
        return HttpResponse(image_data, mimetype=story.mimetype)
    except:
        return HttpResponse('')
Example #2
0
def thumbnail(file, size='200w'):
    filehead, filetail = os.path.split(file.name)
    miniature_url = filehead + '/' + resize_image(file.path, size)
    return miniature_url
Example #3
0
def imageresize(file, size=None):
    miniature = resize_image(file.path, size)
    split = file.url.rsplit('/', 1)
    return '%s/%s' % (split[0], miniature)