-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JpegImagePlugin - while save file pointer write method is not called #1940
Comments
Encoders are complicated, and most of the writes happen in There's not enough info in the test case for me to actually run it. And if it's a Pillow bug, it should be possible to produce a test case that doesn't involve the django stack. For example, this test case works:
Questions I have are:
|
The write method from django-storages has logic uploading file to s3 (I don't know exactly how). Here I found the difference where write is called try:
fh = fp.fileno()
fp.flush()
except (AttributeError, io.UnsupportedOperation):
# compress to Python file-compatible object
for e, b, o, a in tile:
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
if o > 0:
fp.seek(o, 0)
e.setimage(im.im, b)
while True:
l, s, d = e.encode(bufsize)
fp.write(d)
if s:
break
if s < 0:
raise IOError("encoder error %d when writing image file" % s)
e.cleanup()
else:
# slight speedup: compress to real file object
for e, b, o, a in tile:
e = Image._getencoder(im.mode, e, a, im.encoderconfig)
if o > 0:
fp.seek(o, 0)
e.setimage(im.im, b)
s = e.encode_to_file(fh, bufsize)
if s < 0:
raise IOError("encoder error %d when writing image file" % s)
e.cleanup() |
Exactly^ In png case there is an except called (Pdb) fp.fileno()
*** AttributeError: '_idat' object has no attribute 'fileno' |
If you run something like:
Does it succeed? |
This works. Thumbnail is saved where the path points locally |
So, it's not the Jpeg, nor the quality. I'd suggest looking at exactly how django-stores gets the data to S3, either by tempfile or StringIO buffer and enable as much logging as you can around that, including http requests if you can't figure it out any other way. |
FWIW, the writes to file based objects happen within |
I found strange bug with saving jpeg files. PngImagePlugin in
_save
method calls file pointer (fp)write
method whereas in JpegImagePlugin's_save
method it is not used anywhere.What did you do?
I use django-storages to save files on s3 storage. Here is how I generate thumbnails (this is old code)
What did you expect to happen?
Files will be saved on storage.
What actually happened?
With png works ok.
Jpg thumbnailes are not saved.
write
method wasn't call.django-storages returns in
_get_file
methodSpooledTemporaryFile
. With older django-storages version (1.1.8) where instead ofSpooledTemporaryFile
wasStringIO
it worked ok.What versions of Pillow and Python are you using?
2.9.0 and 3.2.0
Please confirm that is Pillow bug.
The text was updated successfully, but these errors were encountered: