当前位置: 首页>>代码示例>>Python>>正文


Python PageData.num_ops方法代码示例

本文整理汇总了Python中main.PageData.num_ops方法的典型用法代码示例。如果您正苦于以下问题:Python PageData.num_ops方法的具体用法?Python PageData.num_ops怎么用?Python PageData.num_ops使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在main.PageData的用法示例。


在下文中一共展示了PageData.num_ops方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: edit_image

# 需要导入模块: from main import PageData [as 别名]
# 或者: from main.PageData import num_ops [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)
开发者ID:cmazuc,项目名称:scarfage,代码行数:83,代码来源:image.py


注:本文中的main.PageData.num_ops方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。