本文整理汇总了Python中wagtail.wagtailimages.formats.get_image_format函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_format函数的具体用法?Python get_image_format怎么用?Python get_image_format使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_image_format函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chooser_select_format
def chooser_select_format(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if request.POST:
form = ImageInsertionForm(request.POST, initial={'alt_text': image.default_alt_text})
if form.is_valid():
format = get_image_format(form.cleaned_data['format'])
preview_image = image.get_rendition(format.filter_spec)
image_json = json.dumps({
'id': image.id,
'title': image.title,
'format': format.name,
'alt': form.cleaned_data['alt_text'],
'class': format.classnames,
'preview': {
'url': preview_image.url,
'width': preview_image.width,
'height': preview_image.height,
},
'html': format.image_to_editor_html(image, form.cleaned_data['alt_text']),
})
return render_modal_workflow(
request, None, 'wagtailimages/chooser/image_chosen.js',
{'image_json': image_json}
)
else:
form = ImageInsertionForm(initial={'alt_text': image.default_alt_text})
return render_modal_workflow(
request, 'wagtailimages/chooser/select_format.html', 'wagtailimages/chooser/select_format.js',
{'image': image, 'form': form}
)
示例2: chooser_select_format
def chooser_select_format(request, image_id):
image = get_object_or_404(get_image_model(), id=image_id)
if request.POST:
form = ImageInsertionForm(request.POST, initial={"alt_text": image.default_alt_text})
if form.is_valid():
format = get_image_format(form.cleaned_data["format"])
preview_image = image.get_rendition(format.filter_spec)
image_json = json.dumps(
{
"id": image.id,
"title": image.title,
"format": format.name,
"alt": form.cleaned_data["alt_text"],
"class": format.classnames,
"preview": {"url": preview_image.url, "width": preview_image.width, "height": preview_image.height},
"html": format.image_to_editor_html(image, form.cleaned_data["alt_text"]),
}
)
return render_modal_workflow(
request, None, "wagtailimages/chooser/image_chosen.js", {"image_json": image_json}
)
else:
form = ImageInsertionForm(initial={"alt_text": image.default_alt_text})
return render_modal_workflow(
request,
"wagtailimages/chooser/select_format.html",
"wagtailimages/chooser/select_format.js",
{"image": image, "form": form},
)
示例3: img_tag
def img_tag(self, extra_attributes=''):
fw_format = get_image_format("fullwidth")
extra_attrs = extra_attributes or ''
if fw_format.filter_spec == self.filter.spec:
return fw_format.image_to_html(
self.image, self.image.title, extra_attrs
)
return super(AffixImageRendition, self).img_tag(extra_attrs)
示例4: expand_db_attributes
def expand_db_attributes(attrs, for_editor):
"""
Given a dict of attributes from the <embed> tag, return the real HTML
representation.
"""
Image = get_image_model()
try:
image = Image.objects.get(id=attrs['id'])
except Image.DoesNotExist:
return "<img>"
image_format = get_image_format(attrs['format'])
if for_editor:
return image_format.image_to_editor_html(image, attrs['alt'])
else:
return image_format.image_to_html(image, attrs['alt'])
示例5: get_image_json
def get_image_json(image):
"""
helper function: given an image, return the json to pass back to the
image chooser panel or the editor to set the poster image
"""
format = get_image_format('left')
preview_image = image.get_rendition(format.filter_spec)
return json.dumps({
'id': image.id,
'title': image.title,
'format': format.name,
'alt': image.title,
'class': format.classnames,
'preview': {
'url': preview_image.url,
'width': preview_image.width,
'height': preview_image.height,
},
'html': format.image_to_editor_html(image, image.title),
})
示例6: test_get_image_format
def test_get_image_format(self):
register_image_format(self.format)
result = get_image_format('test name')
self.assertEqual(result, self.format)
示例7: image_halfwidth
def image_halfwidth(sender, instance, **kwargs):
# Create thumbnails for the image
thumbnail_format = get_image_format("halfwidth")
instance.get_rendition(thumbnail_format.filter_spec)