图片支持问题

2010-09-20 22:57:13 +08:00
 skyonline
如果是所有的图片都能支持的话,下面这段代码该怎样修改呢?
# 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
4509 次点击
所在节点    Project Babel
3 条回复
skyonline
2010-09-21 11:07:54 +08:00
顶下。
skyonline
2010-09-23 08:09:44 +08:00
再顶下
jckwei
2010-09-23 09:39:25 +08:00
路过顶一下

不能包括所有的图片,比如大多数图片url后缀是jpg,gif,png等,
有些图片根本没有后缀,修改正则也只能匹配特定的图片网址类型

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/2767

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX