Subhang V
Subhang V

Reputation: 109

Save image from io.BytesIO

I am trying to convert some code in flask to normal terminal executable python code. But I have come across a certain section of code that tries to return an image as the response to that API call and I would like to store that image.

_, buffer = cv2.imencode('.jpg', img2)

return send_file(
             io.BytesIO(buffer),
             mimetype='image/jpeg',
             as_attachment=True,
             attachment_filename='image.jpg')

How do I re write this part so that I can save it as 'image.jpg'

Upvotes: 0

Views: 1462

Answers (2)

 MALOSS
MALOSS

Reputation: 11

I have to contribute to Mark Setchell: I you want to save jpg with quality setting, just use:

cv2.imwrite('image.jpg', img2, [int(cv2.IMWRITE_JPEG_QUALITY), 100])

Upvotes: 1

Mark Setchell
Mark Setchell

Reputation: 207465

Throw all the code away and just use:

cv2.imwrite('image.jpg', img2)

Upvotes: 1

Related Questions