Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the code below. For some reason it outputs this garbled image:

enter image description here

original:

enter image description here

(I'm not allowed to use any ready-made Python libraries in this exercise)

@app.route("/flip", methods=["POST"])
def flip():

    # retrieve parameters from html form
    if 'horizontal' in request.form['mode']:
        direction = 90
    elif 'vertical' in request.form['mode']:
        direction = -90

    filename = request.form['image']

    # open and process image
    target = os.path.join(APP_ROOT, 'static/images')
    destination = "/".join([target, filename])

    img = Image.open(destination)
    subprocess.call(['C:Program FilesImageMagick-7.0.10-Q16-HDRImagick.exe', 'convert',  f'{destination}', '-rotate', f'{direction}', f'{destination}'], shell=True)
    # save and return image
    destination = "/".join([target, 'flipped.jpg'])
    if os.path.isfile(destination):
        os.remove(destination)
    img.save(destination)
    return send_image('flipped.jpg')

EDIT: when I set the destination image in subprocess.call to flipped.jpg - the output is the original image. Why?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
294 views
Welcome To Ask or Share your Answers For Others

1 Answer

Solved:

    if 'horizontal' in request.form['mode']:
        direction = 'flip'
    elif 'vertical' in request.form['mode']:
        direction = 'flop'
        filename = request.form['image']

    # open and process image
    target = os.path.join(APP_ROOT, 'static/images')
    destination = "/".join([target, filename])
    subprocess.call(['C:Program FilesImageMagick-7.0.10-Q16-HDRImagick.exe', 
                     'convert',  f'{destination}', '-'f'{direction}', f'{destination}'], 
                     shell=True)
    return send_image(filename)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...