本文整理汇总了Python中main.PageData.img方法的典型用法代码示例。如果您正苦于以下问题:Python PageData.img方法的具体用法?Python PageData.img怎么用?Python PageData.img使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类main.PageData
的用法示例。
在下文中一共展示了PageData.img方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: show_image
# 需要导入模块: from main import PageData [as 别名]
# 或者: from main.PageData import img [as 别名]
def show_image(img_id):
pd = PageData()
try:
pd.img = SiteImage.create(img_id)
pd.title=pd.img.tag
except NoImage:
return page_not_found(404)
return render_template('image.html', pd=pd)
示例2: show_image
# 需要导入模块: from main import PageData [as 别名]
# 或者: from main.PageData import img [as 别名]
def show_image(img_id):
"""
:URL: /image/<img_id>
Render a template for viewing an image.
"""
pd = PageData()
try:
pd.img = SiteImage.create(img_id)
pd.title=pd.img.tag
except NoImage:
return page_not_found()
return render_template('image.html', pd=pd)
示例3: edit_image
# 需要导入模块: from main import PageData [as 别名]
# 或者: from main.PageData import img [as 别名]
def edit_image(img_id):
"""
:URL: /image/<img_id>/edit
Very basic image editor. Applies a list of operations to an image
and either presents a preview back to the user or saves it to the
database as a new image.
"""
pd = PageData()
min_size = 200
try:
img = SiteImageEditor(img_id)
except NoImage:
return page_not_found()
preview = request.args.get('preview')
save = request.args.get('save')
pd.img = img
pd.ops = ''
pd.num_ops = 0
for op in range(1,20):
command = request.args.get('op{}'.format(op))
if command:
if command == 'rotate':
degrees = request.args.get('op{}_degrees'.format(op))
try:
degrees = int(degrees)
except:
return page_not_found()
img.rotate(degrees)
pd.ops = "{}&op{}=rotate&op{}_degrees={}".format(pd.ops, op, op, degrees)
pd.num_ops = op
elif command == 'crop':
x1 = request.args.get('op{}_x1'.format(op))
y1 = request.args.get('op{}_y1'.format(op))
x2 = request.args.get('op{}_x2'.format(op))
y2 = request.args.get('op{}_y2'.format(op))
try:
x1 = int(x1)
y1 = int(y1)
x2 = int(x2)
y2 = int(y2)
except:
return page_not_found()
new_width = x2 - x1
new_height = y2 - y1
if new_width < min_size:
flash("The selection is too narrow, please make a larger selection. If your image is below {} pixels in width you will not be able to crop it.".format(min_size))
return redirect_back(url_for('index'))
if new_height < min_size:
flash("The selection is too short, please make a larger selection. If your image is below {} pixels in width you will not be able to crop it.".format(min_size))
return redirect_back(url_for('index'))
img.crop(x1, y1, x2, y2)
pd.ops = "{base}&op{op}=crop&op{op}_x1={x1}&op{op}_y1={y1}&op{op}_x2={x2}&op{op}_y2={y2}".format(base=pd.ops, op=op, x1=x1, y1=y1, x2=x2, y2=y2)
pd.num_ops = op
else:
return page_not_found()
if preview == 'true':
return send_file(img.preview(), mimetype='image/jpeg')
if save:
if 'username' in session:
userid = pd.authuser.uid
else:
userid = None
new_img = img.save(userid, request.remote_addr)
return redirect('/image/' + str(new_img))
return render_template('imageedit.html', pd=pd)