I have the code below. For some reason it outputs this garbled image:
original:
(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?