V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
skyonline
V2EX  ›  Project Babel

图片支持问题

  •  
  •   skyonline · 2010-09-20 22:57:13 +08:00 · 4493 次点击
    这是一个创建于 4971 天前的主题,其中的信息可能已经有所发展或是发生改变。
    如果是所有的图片都能支持的话,下面这段代码该怎样修改呢?
    # auto convert img.ly/abcd links to image tags
    def imgly(value):
    imgs = re.findall('(http://img.ly/[a-zA-Z0-9]+)\s?', value)
    if (len(imgs) > 0):
    for img in imgs:
    img_id = re.findall('http://img.ly/([a-zA-Z0-9]+)', img)
    if (img_id[0] != 'system' and img_id[0] != 'api'):
    value = value.replace('http://img.ly/' + img_id[0], '<a href="http://img.ly/' + img_id[0] + '" target="_blank"><img src="http://zdxproxy.appspot.com/img.ly/show/large/' + img_id[0] + '" class="imgly" border="0" /></a>')
    return value
    else:
    return value
    register.filter(imgly)

    # auto convert cl.ly/abcd links to image tags
    def clly(value):
    imgs = re.findall('(http://cl.ly/[a-zA-Z0-9]+)\s?', value)
    if (len(imgs) > 0):
    for img in imgs:
    img_id = re.findall('http://cl.ly/([a-zA-Z0-9]+)', img)
    if (img_id[0] != 'demo' and img_id[0] != 'whatever'):
    value = value.replace('http://cl.ly/' + img_id[0], '<a href="http://cl.ly/' + img_id[0] + '" target="_blank"><img src="http://cl.ly/' + img_id[0] + '/content" class="imgly" border="0" /></a>')
    return value
    else:
    return value
    3 条回复    1970-01-01 08:00:00 +08:00
    skyonline
        1
    skyonline  
    OP
       2010-09-21 11:07:54 +08:00
    顶下。
    skyonline
        2
    skyonline  
    OP
       2010-09-23 08:09:44 +08:00
    再顶下
    jckwei
        3
    jckwei  
       2010-09-23 09:39:25 +08:00
    路过顶一下

    不能包括所有的图片,比如大多数图片url后缀是jpg,gif,png等,
    有些图片根本没有后缀,修改正则也只能匹配特定的图片网址类型
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   875 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:39 · PVG 03:39 · LAX 12:39 · JFK 15:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.