2016-10-17 03:38:31 +00:00
|
|
|
import io
|
2014-01-04 02:15:08 +00:00
|
|
|
from PIL import Image
|
|
|
|
|
2015-05-30 00:03:28 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def response(flow):
|
2015-09-05 18:45:58 +00:00
|
|
|
if flow.response.headers.get("content-type", "").startswith("image"):
|
2016-07-02 09:01:46 +00:00
|
|
|
try:
|
2016-10-17 03:38:31 +00:00
|
|
|
s = io.StringIO(flow.response.content)
|
2016-07-02 09:01:46 +00:00
|
|
|
img = Image.open(s).rotate(180)
|
2016-10-17 03:38:31 +00:00
|
|
|
s2 = io.StringIO()
|
2016-07-02 09:01:46 +00:00
|
|
|
img.save(s2, "png")
|
|
|
|
flow.response.content = s2.getvalue()
|
|
|
|
flow.response.headers["content-type"] = "image/png"
|
|
|
|
except: # Unknown image types etc.
|
|
|
|
pass
|