The code below takes a JPEG image and converts it to a string. That string is then saved into the image
variable. Then, the string is written to a.jpg
using File IO and then written to b.jpg
by me piping stdout to the file.
import thumb
import sys
x = thumb.Thumbnail('test.jpg')
x.generate(56, 56)
image = str(x)
with open('a.jpg', 'wb') as f:
# saving to a.jpg
f.write(image)
# saving to b.jpg
sys.stdout.write(image)
Usage:
python blah.py > b.jpg
This results in two image files (a.jpg and b.jpg). These images should be identical... But they aren't.
I can see, by looking at each image in Notepad, that linebreaks are, somehow, being added to b.jpg. Resulting in a corrupted image.
Why is a.jpg different to b.jpg?