python类Contrast()的实例源码

solve.py 文件源码 项目:qlcoder 作者: L1nwatch 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def online_rotate_picture(image):
    """
    ?????, ??????
        ????????????????
    :param image:
    :return:
    """
    # ??????????????????????????
    box = image.getbbox()
    width = box[2] - box[0]
    height = box[3] - box[1]
    # print('?????{}??{}??{}'.format(box, width, height))

    # ???????????????????
    region = image.crop((box[0], box[1], box[2], box[1] + 1))
    box2 = region.getbbox()
    mid = width / 2
    if box2[0] < mid < box2[2]:
        # ???????? ?????
        return image
    adjacent = max(box2[0], width - box2[2])  # ??
    # print('?????{}???{}'.format(box2, adjacent))

    # ???????????????????
    region = image.crop((box[0], box[1], box[0] + 1, box[3]))
    box3 = region.getbbox()
    opposite = max(box3[1], height - box3[3])  # ??
    # print('?????{}???{}'.format(box3, opposite))

    import math
    angle = math.atan(opposite / adjacent) / math.pi * 180

    if box2[0] > mid:
        # ?????????????????????????
        angle = - angle
    # print('??????{}'.format(int(angle)))

    # ??
    size = image.size
    ret = image.resize((size[0] * 2, size[1] * 2), Image.ANTIALIAS)

    # ??
    ret = ret.rotate(angle)

    # ?????????????????
    from PIL import ImageEnhance
    ret = ImageEnhance.Contrast(ret)
    ret = ret.enhance(2)

    # ??
    ret = ret.crop(ret.getbbox())

    # box = image.getbbox()
    # width = box[2] - box[0]
    # height = box[3] - box[1]
    # print('?????{}??{}??{}'.format(box, width, height))

    return ret
CuteR.py 文件源码 项目:CuteR 作者: chinuno-usami 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def main():
    import argparse
    parser = argparse.ArgumentParser(description="Combine your QR code with custom picture")
    parser.add_argument("image")
    parser.add_argument("text", help="QRcode Text.")
    parser.add_argument("-o", "--output", help="Name of output file.")
    parser.add_argument("-v", "--version", type=int, help="QR version.In range of [1-40]")
    parser.add_argument("-e", "--errorcorrect", choices={"L","M","Q","H"}, help="Error correct")
    parser.add_argument("-b", "--brightness", type=float, help="Brightness enhance")
    parser.add_argument("-c", "--contrast", type=float, help="Contrast enhance")
    parser.add_argument("-C", "--colourful", action="store_true",help="colourful mode")
    parser.add_argument("-r", "--rgba", nargs=4, metavar=('R','G','B','A'),type = int, help="color to replace black")
    parser.add_argument("-p", "--pixelate", action="store_true",help="pixelate")
    args = parser.parse_args()

    img = args.image
    txt = args.text
    output = args.output if args.output else 'qr.png'
    ec = qrcode.constants.ERROR_CORRECT_H
    if args.errorcorrect:
        ec_raw = args.errorcorrect
        if ec_raw == 'L':
            ec = qrcode.constants.ERROR_CORRECT_L
        if ec_raw == 'M':
            ec = qrcode.constants.ERROR_CORRECT_M
        if ec_raw == 'Q':
            ec = qrcode.constants.ERROR_CORRECT_Q
    ver = 5
    if args.version:
        if args.version >= 1 and args.version <= 40:
            ver = args.version
    cont = args.contrast if args.contrast else 1.0
    bri = args.brightness if args.brightness else 1.0
    colr = True if args.colourful else False
    pixelate = True if args.pixelate else False
    if colr :
        if args.rgba:
          rgba = tuple(args.rgba)
        else:
            rgba = (0,0,0,255)
    else:
        rgba = (0,0,0,255)
    frames = produce(txt,img,ver,ec,bri, cont ,colourful = colr,rgba=rgba,pixelate = pixelate)
    if len(frames) == 1 or output.upper()[-3:] != "GIF":
        frames[0].save(output)
    elif len(frames) > 1:
        frames[0].save(output,save_all=True,append_images=frames[1:],duration=100,optimize=True)


问题


面经


文章

微信
公众号

扫码关注公众号