當前位置: 首頁>>代碼示例>>Python>>正文


Python PageData.ops方法代碼示例

本文整理匯總了Python中main.PageData.ops方法的典型用法代碼示例。如果您正苦於以下問題:Python PageData.ops方法的具體用法?Python PageData.ops怎麽用?Python PageData.ops使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在main.PageData的用法示例。


在下文中一共展示了PageData.ops方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: edit_image

# 需要導入模塊: from main import PageData [as 別名]
# 或者: from main.PageData import 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.ops方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。