本文整理汇总了Python中mezzanine.core.templatetags.mezzanine_tags.thumbnail函数的典型用法代码示例。如果您正苦于以下问题:Python thumbnail函数的具体用法?Python thumbnail怎么用?Python thumbnail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了thumbnail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_thumbnail_generation
def test_thumbnail_generation(self):
"""
Test that a thumbnail is created and resized.
"""
try:
from PIL import Image
except ImportError:
return
image_name = "image.jpg"
size = (24, 24)
copy_test_to_media("mezzanine.core", image_name)
thumb_name = os.path.join(settings.THUMBNAILS_DIR_NAME,
"thumbs-%s" % image_name,
image_name.replace(".", "-%sx%s." % size))
thumb_path = os.path.join(settings.MEDIA_ROOT, thumb_name)
thumb_image = thumbnail(image_name, *size)
self.assertEqual(os.path.normpath(thumb_image.lstrip("/")), thumb_name)
self.assertNotEqual(os.path.getsize(thumb_path), 0)
thumb = Image.open(thumb_path)
self.assertEqual(thumb.size, size)
# Clean up.
del thumb
os.remove(os.path.join(settings.MEDIA_ROOT, image_name))
os.remove(os.path.join(thumb_path))
rmtree(os.path.join(os.path.dirname(thumb_path)))
开发者ID:DamavandiKamali,项目名称:mezzanine,代码行数:25,代码来源:tests.py
示例2: image
def image(content, width, height):
if not content.image_scaling:
return content.image
if content.image_width or content.image_height:
width = content.image_width
height = content.image_height
return thumbnail(content.image, width, height, int(content.image_quality))
开发者ID:wrwrwr,项目名称:mezzanine-addons,代码行数:7,代码来源:content.py
示例3: get_thumbnail_url
def get_thumbnail_url(self):
"""
A url that serves the thumbnail of the image (Creates one if none yet
exists)
"""
# FIXME: Make the parameters configurable
return settings.MEDIA_URL + thumbnail(self.get_absolute_url(), 400, 200)
开发者ID:transformersprimeabcxyz,项目名称:raspberryio-python,代码行数:7,代码来源:models.py
示例4: admin_thumb
def admin_thumb(self):
if self.image is None:
return ""
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
thumb_url = thumbnail(self.image, 24, 24)
return "<img src='%s%s' />" % (settings.MEDIA_URL, thumb_url)
开发者ID:skyfion,项目名称:cartridge,代码行数:7,代码来源:models.py
示例5: thumbnails
def thumbnails(html):
"""
Given a HTML string, converts paths in img tags to thumbnail
paths, using Mezzanine's ``thumbnail`` template tag. Used as
one of the default values in the ``RICHTEXT_FILTERS`` setting.
"""
from django.conf import settings
from html5lib import parse
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
dom = parse(html, treebuilder="dom")
for img in dom.getElementsByTagName("img"):
src = img.getAttribute("src")
width = img.getAttribute("width")
height = img.getAttribute("height")
if src and width and height:
src = settings.MEDIA_URL + thumbnail(src, width, height)
img.setAttribute("src", src)
output = []
for parent in ("head", "body"):
for node in dom.getElementsByTagName(parent)[0].childNodes:
output.append(node.toxml())
if node.localName == "script":
output.append("</script>")
return "".join(output)
开发者ID:11m09d,项目名称:weixin_market,代码行数:25,代码来源:html.py
示例6: thumbnails
def thumbnails(html):
"""
Given a HTML string, converts paths in img tags to thumbnail
paths, using Mezzanine's ``thumbnail`` template tag. Used as
one of the default values in the ``RICHTEXT_FILTERS`` setting.
"""
from django.conf import settings
from bs4 import BeautifulSoup
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
# If MEDIA_URL isn't in the HTML string, there aren't any
# images to replace, so bail early.
if settings.MEDIA_URL.lower() not in html.lower():
return html
dom = BeautifulSoup(html, "html.parser")
for img in dom.findAll("img"):
src = img.get("src", "")
src_in_media = src.lower().startswith(settings.MEDIA_URL.lower())
width = img.get("width")
height = img.get("height")
if src_in_media and str(width).isdigit() and str(height).isdigit():
img["src"] = settings.MEDIA_URL + thumbnail(src, width, height)
# BS adds closing br tags, which the browser interprets as br tags.
return str(dom).replace("</br>", "")
开发者ID:kelvinwong-ca,项目名称:mezzanine,代码行数:25,代码来源:html.py
示例7: get_thumb_url
def get_thumb_url(self):
thumb = None
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, None)
if thumb is None:
return ""
return "%s%s" % (settings.MEDIA_URL, thumbnail(thumb, self.width, self.height, self.quality))
开发者ID:HuntedHive,项目名称:mezzanine-blocks,代码行数:8,代码来源:models.py
示例8: render
def render(self, name, value, attrs):
rendered = super(ImageWidget, self).render(name, value, attrs)
if value:
orig = u"%s%s" % (settings.MEDIA_URL, value)
thumb = u"%s%s" % (settings.MEDIA_URL, thumbnail(value, 48, 48))
rendered = (u"<a target='_blank' href='%s'>"
u"<img style='margin-right:6px;' src='%s'>"
u"</a>%s" % (orig, thumb, rendered))
return mark_safe(rendered)
开发者ID:DanielLoeb,项目名称:cartridge,代码行数:9,代码来源:forms.py
示例9: get_thumb_url
def get_thumb_url(self):
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
thumb = None
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, None)
if thumb is None:
return ""
return "%s%s" % (settings.MEDIA_URL, thumbnail(thumb, self.width, self.height, self.quality))
开发者ID:christianwgd,项目名称:mezzanine-blocks,代码行数:9,代码来源:models.py
示例10: admin_thumb
def admin_thumb(self):
thumb = None
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, None)
if thumb is None:
return ""
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
thumb_url = thumbnail(thumb, 24, 24)
return "<img src='%s%s'>" % (settings.MEDIA_URL, thumb_url)
开发者ID:CreunaAB,项目名称:mezzanine,代码行数:9,代码来源:models.py
示例11: render
def render(self, name, value, attrs):
rendered = super(ImageWidgetBase, self).render(name, value, attrs)
if value:
orig = '%s%s' % (settings.MEDIA_URL, value)
thumb = '%s%s' % (settings.MEDIA_URL, thumbnail(value, 48, 48))
rendered = ('<a href="%s"> target="_blank"'
'<img style="margin-right: 6px;" src="%s">'
'</a><span class="clearable-image">%s</span>' %
(orig, thumb, rendered))
return mark_safe(rendered)
开发者ID:wrwrwr,项目名称:mezzanine-addons,代码行数:10,代码来源:forms.py
示例12: admin_thumb
def admin_thumb(self):
thumb = None
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, None)
if thumb is None:
return ""
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
x, y = settings.ADMIN_THUMB_SIZE.split('x')
thumb_url = thumbnail(thumb, x, y)
return "<img src='%s%s'>" % (settings.MEDIA_URL, thumb_url)
开发者ID:aTnT,项目名称:mezzanine-dotcloud,代码行数:10,代码来源:models.py
示例13: admin_thumb
def admin_thumb(self):
thumb = ""
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, "")
if not thumb:
return ""
from mezzanine.conf import settings
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
x, y = 160, 90
thumb_url = thumbnail(thumb, x, y)
return "<img src='%s%s'>" % (settings.MEDIA_URL, thumb_url)
开发者ID:moinfar,项目名称:SSC_Site,代码行数:11,代码来源:models.py
示例14: admin_thumb
def admin_thumb(self):
thumb = ""
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, "")
if not thumb:
return ""
from mezzanine.conf import settings
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
x, y = settings.ADMIN_THUMB_SIZE.split('x')
thumb_url = thumbnail(thumb, x, y)
return format_html("<img src='{}{}'>", settings.MEDIA_URL, thumb_url)
开发者ID:ctrengove,项目名称:mezzanine,代码行数:11,代码来源:models.py
示例15: get_thumb_url
def get_thumb_url(self):
thumb = None
if self.admin_thumb_field:
thumb = getattr(self, self.admin_thumb_field, None)
if thumb is None:
return ""
url = thumbnail(thumb.path, self.width,
self.height, self.quality)
# When using differing storage backends,
# such as Boto and S3 appears that file path
# can be stored as absolute rather than relative path
url_obj = urlparse(url)
if url_obj.scheme not in ['http', 'https']:
url = "%s%s" % (settings.MEDIA_URL, url)
return url
开发者ID:boardman,项目名称:mezzanine-blocks,代码行数:17,代码来源:models.py
示例16: makeTag
def makeTag(self, href, title, text):
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
el = util.etree.Element("img")
small_thumbnail_href = settings.MEDIA_URL + thumbnail(href, 30, 0)
el.set("src", small_thumbnail_href)
if title:
el.set("title", title)
if self.markdown.enable_attributes:
text = handleAttributes(text, el)
el.set("alt", self.unescape(text))
el.set('class', 'img-responsive blog-detail-featured-image progressive__img progressive--not-loaded')
el.set("data-progressive", self.sanitize_url(href))
return el
开发者ID:phodal,项目名称:phodaldev,代码行数:18,代码来源:progressiveimage.py
示例17: thumbnails
def thumbnails(html):
"""
Given a HTML string, converts paths in img tags to thumbnail
paths, using Mezzanine's ``thumbnail`` template tag. Used as
one of the default values in the ``RICHTEXT_FILTERS`` setting.
"""
from django.conf import settings
from bs4 import BeautifulSoup
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
dom = BeautifulSoup(html)
for img in dom.findAll("img"):
src = img.get("src", "")
src_in_media = src.lower().startswith(settings.MEDIA_URL.lower())
width = img.get("width")
height = img.get("height")
if src_in_media and width and height:
img["src"] = settings.MEDIA_URL + thumbnail(src, width, height)
return str(dom)
开发者ID:Catalyst4Success,项目名称:site-django-mezzanine,代码行数:19,代码来源:html.py
示例18: test_thumbnail_generation
def test_thumbnail_generation(self):
"""
Test that a thumbnail is created.
"""
original_name = "testleaf.jpg"
if not os.path.exists(os.path.join(settings.MEDIA_ROOT, original_name)):
return
thumbnail_name = "testleaf-24x24.jpg"
thumbnail_path = os.path.join(settings.MEDIA_ROOT, thumbnail_name)
try:
os.remove(thumbnail_path)
except OSError:
pass
thumbnail_image = thumbnail(original_name, 24, 24)
self.assertEqual(thumbnail_image.lstrip("/"), thumbnail_name)
self.assertNotEqual(0, os.path.getsize(thumbnail_path))
try:
os.remove(thumbnail_path)
except OSError:
pass
开发者ID:chrishas35,项目名称:mezzanine,代码行数:20,代码来源:tests.py
示例19: thumbnails
def thumbnails(html):
"""
Given a HTML string, converts paths in img tags to thumbnail
paths, using Mezzanine's ``thumbnail`` template tag. Used as
one of the default values in the ``RICHTEXT_FILTERS`` setting.
"""
from django.conf import settings
from html5lib.treebuilders import getTreeBuilder
from html5lib.html5parser import HTMLParser
from mezzanine.core.templatetags.mezzanine_tags import thumbnail
dom = HTMLParser(tree=getTreeBuilder("dom")).parse(html)
for img in dom.getElementsByTagName("img"):
src = img.getAttribute("src")
width = img.getAttribute("width")
height = img.getAttribute("height")
if src and width and height:
src = settings.MEDIA_URL + thumbnail(src, width, height)
img.setAttribute("src", src)
nodes = dom.getElementsByTagName("body")[0].childNodes
return "".join([node.toxml() for node in nodes])
开发者ID:Kulak,项目名称:mezzanine,代码行数:21,代码来源:html.py
示例20: make_thumb
def make_thumb(image_abs_list, image_dir):
MAXWIDTH = 980
MAXHEIGHT = 600
DELTA = 50
thumb_dir = os.path.join(image_dir, settings.THUMBNAILS_DIR_NAME)
thumb_list = []
for image_name in image_abs_list:
image_base = os.path.basename(image_name)
img = Image.open(image_name)
w, h = img.size
if w == h or abs(w - h) < DELTA:
size = (MAXHEIGHT, MAXHEIGHT)
elif w > h: #landscape image
if w / float(h) > 1.5:
size = (MAXWIDTH, 0)
else:
size = (0, MAXHEIGHT)
else:
size = (0, MAXHEIGHT)
image_base = os.path.splitext(image_base)
thumb_image = os.path.join(thumb_dir, image_base[0]+ "-%sx%s" % size+ image_base[1])
if not os.path.exists(thumb_image):
print "Processing", thumb_image
thumb_image = thumbnail(image_name, *size)
thumb_list.append(os.path.basename(thumb_image))
#else: print "skipping", thumb_image
### Move original file
orig_dir = os.path.join(image_dir, 'orig')
if not os.path.exists(orig_dir):
os.makedirs(orig_dir)
shutil.move(image_name, orig_dir)
return thumb_list
开发者ID:food4code,项目名称:computedart,代码行数:36,代码来源:views.py
注:本文中的mezzanine.core.templatetags.mezzanine_tags.thumbnail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论