本文整理汇总了Python中nnmware.core.imgutil.make_thumbnail函数的典型用法代码示例。如果您正苦于以下问题:Python make_thumbnail函数的具体用法?Python make_thumbnail怎么用?Python make_thumbnail使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_thumbnail函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _ajax_upload
def _ajax_upload(self, request, **kwargs):
if request.method == "POST":
tmb = None
self._upload_file(request, **kwargs)
fullpath = os.path.join(settings.MEDIA_ROOT, self.extra_context['path'])
try:
i = Image.open(fullpath)
except:
messages.error(request, "File is not image format")
os.remove(fullpath)
self.success = False
self.pic_id = None
if self.success:
ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
object_id = int(kwargs['object_id'])
obj = ctype.get_object_for_this_type(pk=object_id)
try:
remove_thumbnails(obj.img.path)
remove_file(obj.img.path)
obj.img.delete()
except:
pass
obj.img = self.extra_context['path']
obj.save()
# let Ajax Upload know whether we saved it or not
addons = {'tmb': make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
aspect=int(kwargs['aspect']))}
payload = {'success': self.success, 'filename': self.filename}
if self.extra_context is not None:
payload.update(self.extra_context)
if addons:
payload.update(addons)
return AjaxAnswer(payload)
开发者ID:wallaceosmar,项目名称:nnmware,代码行数:33,代码来源:ajax.py
示例2: add_related_product
def add_related_product(request, object_id):
try:
if not request.user.is_superuser:
raise AccessError
p = get_object_or_404(Product, pk=int(object_id))
product = get_object_or_404(Product, pk=int(request.POST["product"]))
p.related_products.add(product)
p.save()
payload = {
"success": True,
"name": product.name,
"id": product.pk,
"url": product.get_absolute_url(),
"src": make_thumbnail(
product.main_image,
width=settings.RELATED_PRODUCT_WIDTH,
height=settings.RELATED_PRODUCT_HEIGHT,
aspect=1,
),
}
except AccessError:
payload = {"success": False}
except:
payload = {"success": False}
return AjaxLazyAnswer(payload)
开发者ID:kingctan,项目名称:nnmware,代码行数:25,代码来源:ajax.py
示例3: _ajax_upload
def _ajax_upload(self, request, **kwargs):
if request.method == "POST":
self._upload_file(request, **kwargs)
fullpath = os.path.join(settings.MEDIA_ROOT, self.extra_context["path"])
try:
i = Image.open(fullpath)
except:
messages.error(request, "File is not image format")
os.remove(fullpath)
self.success = False
self.pic_id = None
addons = None
if self.success:
new = Pic()
self._new_obj(new, request, **kwargs)
new.pic = self.extra_context["path"]
fullpath = os.path.join(settings.MEDIA_ROOT, new.pic.field.upload_to, new.pic.path)
new.size = os.path.getsize(fullpath)
new.save()
self.pic_id = new.pk
# let Ajax Upload know whether we saved it or not
addons = {
"size": os.path.getsize(fullpath),
"thumbnail": make_thumbnail(new.pic.url, width=settings.DEFAULT_UPLOAD_THUMBNAIL_SIZE),
}
payload = {"success": self.success, "filename": self.filename, "id": self.pic_id}
if self.extra_context is not None:
payload.update(self.extra_context)
if addons:
payload.update(addons)
return AjaxAnswer(payload)
开发者ID:ksenor,项目名称:nnmware,代码行数:31,代码来源:ajax.py
示例4: pic_getcrop
def pic_getcrop(request, object_id):
# Link used for User want crop image
pic = get_object_or_404(Pic, id=int(object_id))
try:
payload = dict(success=True, src=make_thumbnail(pic.pic.url, width=settings.MAX_IMAGE_CROP_WIDTH), id=pic.pk)
except:
payload = {'success': False}
return AjaxLazyAnswer(payload)
开发者ID:wallaceosmar,项目名称:nnmware,代码行数:8,代码来源:ajax.py
示例5: img_getcrop
def img_getcrop(request, object_id):
# Link used for User want crop image
pic = get_object_or_404(Pic, id=int(object_id))
try:
payload = dict(success=True, src=make_thumbnail(pic.pic.url, width=MAX_IMAGE_CROP_WIDTH), id=pic.pk)
except:
payload = dict(success=False)
return ajax_answer_lazy(payload)
开发者ID:cihatkk,项目名称:nnmware,代码行数:8,代码来源:ajax.py
示例6: slide_thumbnail
def slide_thumbnail(self):
if self.img:
path = self.img.url
tmb = make_thumbnail(path, width=60, height=60, aspect=1)
else:
tmb = '/static/img/icon-no.gif"'
path = '/static/img/icon-no.gif"'
return '<a target="_blank" href="%s"><img src="%s" /></a>' % (path, tmb)
开发者ID:krast,项目名称:nnmware,代码行数:8,代码来源:abstract.py
示例7: thumbnail
def thumbnail(self):
if self.img:
path = self.img.url
tmb = make_thumbnail(path, height=60, width=60)
return '<a style="display:block;text-align:center;" target="_blank" href="%s"><img src="%s" /></a>' \
'<p style="text-align:center;margin-top:5px;">%sx%s px</p>' % (path, tmb, self.img_width,
self.img_height)
return "No image"
开发者ID:krast,项目名称:nnmware,代码行数:8,代码来源:abstract.py
示例8: img_getcrop
def img_getcrop(request, object_id):
# Link used for User want crop image
pic = get_object_or_404(Pic, id=int(object_id))
try:
payload = {
"success": True,
"src": make_thumbnail(pic.pic.url, width=settings.MAX_IMAGE_CROP_WIDTH),
"id": pic.pk,
}
except:
payload = {"success": False}
return AjaxLazyAnswer(payload)
开发者ID:ksenor,项目名称:nnmware,代码行数:12,代码来源:ajax.py
示例9: autocomplete_search
def autocomplete_search(request,size=16):
results = []
search_qs = Product.objects.filter(
Q(name__icontains=request.REQUEST['q']) |
Q(name_en__icontains=request.REQUEST['q'])).order_by('name')[:5]
for r in search_qs:
img = make_thumbnail(r.main_image,width=int(size))
userstring = {'name': r.name, 'path': r.get_absolute_url(),
'img': img,
'slug': r.slug, 'amount':"%0.2f" % (r.amount,),'id':r.pk }
results.append(userstring)
payload = {'answer': results}
return AjaxLazyAnswer(payload)
开发者ID:MrTomato8,项目名称:nnmware,代码行数:13,代码来源:ajax.py
示例10: thumbnail
def thumbnail(url, args=''):
""" Returns thumbnail URL and create it if not already exists.
Usage::
{{ url|thumbnail:"width=10,height=20" }}
{{ url|thumbnail:"width=10" }}
{{ url|thumbnail:"height=20,aspect=1" }}
Image is **proportionally** resized to dimension which is no greater than ``width x height``.
Thumbnail file is saved in the same location as the original image
and his name is constructed like this::
%(dirname)s/%(basename)s_t[_w%(width)d][_h%(height)d].%(extension)s
or if only a width is requested (to be compatibile with admin interface)::
%(dirname)s/%(basename)s_t%(width)d.%(extension)s
"""
if url is None:
return None
kwargs = {}
if args:
if ',' not in args:
# ensure at least one ','
args += ','
for arg in args.split(','):
arg = arg.strip()
if arg == '':
continue
kw, val = arg.split('=', 1)
kw = kw.lower().encode('ascii')
try:
val = int(val) # convert all ints
except ValueError:
raise TemplateSyntaxError
kwargs[kw] = val
if ('width' not in kwargs) and ('height' not in kwargs):
raise TemplateSyntaxError
ret = make_thumbnail(url, **kwargs)
if ret is None:
ret = url
if not ret.startswith(settings.MEDIA_URL):
ret = settings.MEDIA_URL + ret
return ret
开发者ID:biomassives,项目名称:nnmware,代码行数:50,代码来源:core.py
示例11: hotels_in_country
def hotels_in_country(request):
try:
results = []
for hotel in Hotel.objects.all().order_by('starcount'):
answer = {'name':hotel.get_name, 'latitude':hotel.latitude,'url':hotel.get_absolute_url(),
'address':hotel.address,'id':hotel.pk,'starcount':hotel.starcount,
'img':make_thumbnail(hotel.main_image,width=113,height=75,aspect=1),
'longitude':hotel.longitude, 'starcount_name':hotel.get_starcount_display(),
'amount':str(int(hotel.current_amount ))}
results.append(answer)
payload = {'success': True, 'hotels':results}
except :
payload = {'success': False}
return AjaxLazyAnswer(payload)
开发者ID:MrTomato8,项目名称:nnmware,代码行数:14,代码来源:ajax.py
示例12: ajax_get_thumbnail
def ajax_get_thumbnail(request):
img_pk = int(request.POST['image_id'])
pic = get_object_or_404(Pic, id=int(img_pk))
width = request.POST.get('width') or None
height = request.POST.get('height') or None
if width:
width = int(width)
if height:
height = int(height)
try:
payload = dict(success=True, src=make_thumbnail(pic.pic.url, width=width, height=height), id=pic.pk)
except:
payload = {'success': False}
return ajax_answer_lazy(payload)
开发者ID:cihatkk,项目名称:nnmware,代码行数:14,代码来源:ajax.py
示例13: filter_hotels_on_map
def filter_hotels_on_map(request, hotels):
try:
searched = hotels
f_date = request.POST.get("start_date") or None
amount_min = request.POST.get("amount_min") or None
amount_max = request.POST.get("amount_max") or None
options = request.POST.getlist("options") or None
stars = request.POST.getlist("stars") or None
if amount_max and amount_min:
if f_date:
from_date = convert_to_date(f_date)
hotels_with_amount = (
PlacePrice.objects.filter(date=from_date, amount__range=(amount_min, amount_max))
.values_list("settlement__room__hotel__pk", flat=True)
.distinct()
)
else:
hotels_with_amount = (
PlacePrice.objects.filter(date=now(), amount__range=(amount_min, amount_max))
.values_list("settlement__room__hotel__pk", flat=True)
.distinct()
)
searched = searched.filter(pk__in=hotels_with_amount, work_on_request=False)
if options:
for option in options:
searched = searched.filter(option=option)
if stars:
searched = searched.filter(starcount__in=stars)
searched = searched.order_by("starcount")
results = []
for hotel in searched:
answer = {
"name": hotel.get_name,
"latitude": hotel.latitude,
"url": hotel.get_absolute_url(),
"address": hotel.address,
"id": hotel.pk,
"starcount": hotel.starcount,
"img": make_thumbnail(hotel.main_image, width=113, height=75, aspect=1),
"longitude": hotel.longitude,
"starcount_name": hotel.get_starcount_display(),
"amount": str(int(hotel.current_amount)),
}
results.append(answer)
payload = {"success": True, "hotels": results}
except:
payload = {"success": False}
return ajax_answer_lazy(payload)
开发者ID:nnmware,项目名称:nnmware,代码行数:49,代码来源:ajax.py
示例14: add_related_product
def add_related_product(request,object_id):
try:
if not request.user.is_superuser:
raise AccessError
p = get_object_or_404(Product,pk=int(object_id))
product = get_object_or_404(Product,pk=int(request.REQUEST['product']))
p.related_products.add(product)
p.save()
payload = {'success': True, 'name':product.name, 'id': product.pk, 'url':product.get_absolute_url(),
'src': make_thumbnail(product.main_image,width=settings.RELATED_PRODUCT_WIDTH,height=settings.RELATED_PRODUCT_HEIGHT, aspect=1)}
except AccessError:
payload = {'success': False}
except :
payload = {'success': False}
return AjaxLazyAnswer(payload)
开发者ID:ir4y,项目名称:nnmware,代码行数:15,代码来源:ajax.py
示例15: AjaxGetThumbnail
def AjaxGetThumbnail(request):
img_pk = int(request.REQUEST['image_id'])
pic = get_object_or_404(Pic, id=int(img_pk))
width = request.REQUEST.get('width') or None
height = request.REQUEST.get('height') or None
if width:
width = int(width)
if height:
height = int(height)
try:
payload = {'success': True,
'src': make_thumbnail(pic.pic.url,width=width,height=height),
'id':pic.pk}
except :
payload = {'success': False}
return AjaxLazyAnswer(payload)
开发者ID:MrTomato8,项目名称:nnmware,代码行数:16,代码来源:ajax.py
示例16: add_color
def add_color(request, object_id):
try:
if not request.user.is_superuser:
raise AccessError
p = get_object_or_404(Product, pk=int(object_id))
color = get_object_or_404(ProductColor, pk=int(request.REQUEST['color']))
w = int(request.REQUEST['width'])
h = int(request.REQUEST['height'])
p.colors.add(color)
p.save()
payload = {'success': True, 'name': color.name, 'id': color.pk,
'src': make_thumbnail(color.img.url, width=w, height=h)}
except AccessError:
payload = {'success': False}
except:
payload = {'success': False}
return AjaxLazyAnswer(payload)
开发者ID:kindlejiang,项目名称:nnmware,代码行数:17,代码来源:ajax.py
示例17: autocomplete_search
def autocomplete_search(request, size=16):
results = []
search_qs = Product.objects.filter(
Q(name__icontains=request.POST["q"]) | Q(name_en__icontains=request.POST["q"])
).order_by("name")[:5]
for r in search_qs:
img = make_thumbnail(r.main_image, width=int(size))
userstring = {
"name": r.name,
"path": r.get_absolute_url(),
"img": img,
"slug": r.slug,
"amount": "%0.2f" % (r.amount,),
"id": r.pk,
}
results.append(userstring)
payload = {"answer": results}
return AjaxLazyAnswer(payload)
开发者ID:kingctan,项目名称:nnmware,代码行数:18,代码来源:ajax.py
示例18: add_color
def add_color(request, object_id):
try:
if not request.user.is_superuser:
raise AccessError
p = get_object_or_404(Product, pk=int(object_id))
color = get_object_or_404(ProductColor, pk=int(request.POST["color"]))
w = int(request.POST["width"])
h = int(request.POST["height"])
p.colors.add(color)
p.save()
payload = {
"success": True,
"name": color.name,
"id": color.pk,
"src": make_thumbnail(color.img.url, width=w, height=h),
}
except AccessError:
payload = {"success": False}
except:
payload = {"success": False}
return AjaxLazyAnswer(payload)
开发者ID:kingctan,项目名称:nnmware,代码行数:21,代码来源:ajax.py
示例19: filter_hotels_on_map
def filter_hotels_on_map(request, hotels):
try:
searched = hotels
f_date = request.POST.get('start_date') or None
amount_min = request.POST.get('amount_min') or None
amount_max = request.POST.get('amount_max') or None
options = request.POST.getlist('options') or None
stars = request.POST.getlist('stars') or None
if amount_max and amount_min:
if f_date:
from_date = convert_to_date(f_date)
hotels_with_amount = PlacePrice.objects.filter(date=from_date,
amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
flat=True).distinct()
else:
hotels_with_amount = PlacePrice.objects.filter(date=now(),
amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
flat=True).distinct()
searched = searched.filter(pk__in=hotels_with_amount, work_on_request=False)
if options:
for option in options:
searched = searched.filter(option=option)
if stars:
searched = searched.filter(starcount__in=stars)
searched = searched.order_by('starcount')
results = []
for hotel in searched:
answer = {'name': hotel.get_name, 'latitude': hotel.latitude, 'url': hotel.get_absolute_url(),
'address': hotel.address, 'id': hotel.pk, 'starcount': hotel.starcount,
'img': make_thumbnail(hotel.main_image, width=113, height=75, aspect=1),
'longitude': hotel.longitude, 'starcount_name': hotel.get_starcount_display(),
'amount': str(int(hotel.current_amount))}
results.append(answer)
payload = {'success': True, 'hotels': results}
except:
payload = {'success': False}
return ajax_answer_lazy(payload)
开发者ID:cdrone-hotels,项目名称:nnmware,代码行数:38,代码来源:ajax.py
示例20: file_uploader
def file_uploader(request, **kwargs):
uploader = AjaxUploader(filetype='image', upload_dir=setting('IMAGE_UPLOAD_DIR', 'images'),
size_limit=setting('IMAGE_UPLOAD_SIZE', 10485760))
result = uploader.handle_upload(request)
if result['success']:
ctype = get_object_or_404(ContentType, id=int(kwargs['content_type']))
object_id = int(kwargs['object_id'])
obj = ctype.get_object_for_this_type(pk=object_id)
try:
remove_thumbnails(obj.img.path)
remove_file(obj.img.path)
obj.img.delete()
except:
pass
obj.img = result['path']
obj.save()
try:
addons = dict(tmb=make_thumbnail(obj.img.url, width=int(kwargs['width']), height=int(kwargs['height']),
aspect=int(kwargs['aspect'])))
except:
addons = {}
result.update(addons)
return AjaxAnswer(result)
开发者ID:wallaceosmar,项目名称:nnmware,代码行数:23,代码来源:ajax.py
注:本文中的nnmware.core.imgutil.make_thumbnail函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论