Login

iPernity thumbnail helper

Author:
sedden
Posted:
November 15, 2008
Language:
Python
Version:
1.0
Tags:
template image thumbnail resize ipernity
Score:
0 (after 0 ratings)

A simple template filter that detects iPernity static URLs and creates clickable thumbnail for them. Use it with Lightbox or any other funky image overlay script.

Your HTML code may contain this:

<p>A short example <img
src="http://...ipernity..."
title="The Description" />.</p>

After applying this filter it will become:

<p>A short example <a 
href="http://...large version..."
title="The Title"><img 
alt="The Title"
src="http://...thumb version..."/>
</a>.</p>

Thats all! You may have a look at this: iPernity and static URLs

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django import template

from BeautifulSoup import BeautifulSoup, Tag 
import re

register = template.Library()

@register.filter(name="iperlink")
def do_iperimage(value):

        soup = BeautifulSoup(value)
        iprl = re.compile('^(http://\w+\.ipernity\.com/\d+/\d+/\d+/\d+\.\w+\.)(75|100|240|500|560)(\.jpg)$')
        iprl_thumb = '240'
        iprl_zoom = '560'

        for img in soup.findAll('img', src=iprl ):

                match = iprl.match(img['src'])
                try:
                        thumb = Tag(soup, 'img')
                        thumb['alt'] = img['title']
                        thumb['src'] = match.group(1)+iprl_thumb+match.group(3)

                        link = Tag(soup, 'a')
                        link['href'] = match.group(1)+iprl_zoom+match.group(3)
                        link['rel'] = 'lightbox'
                        link['title'] = img['title']
                        link.insert(0, thumb)

                        img.replaceWith(link)
                except:
                        pass        
            
        return unicode(soup)

do_iperimage.is_safe = True

More like this

  1. [UPDATE]Filter to resize a ImageField on demand by rafacdb 6 years, 12 months ago
  2. UPDATED: Django Image Thumbnail Filter by danfairs 7 years, 9 months ago
  3. Auto Generate/Save Thumbnails using Template Filter (scale max_x, max_y, or both) by ThisbeTom 6 years, 7 months ago
  4. AddThis Social Networking TemplateTag by yeago 6 years, 7 months ago
  5. Photologue wiki-syntax templatetag by yeago 6 years, 10 months ago

Comments

Please login first before commenting.