Skip to content
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

Upload Issue - No Resized Images Generated #153

Closed
digitalhurricane-io opened this issue Aug 1, 2017 · 9 comments
Closed

Upload Issue - No Resized Images Generated #153

digitalhurricane-io opened this issue Aug 1, 2017 · 9 comments

Comments

@digitalhurricane-io
Copy link

digitalhurricane-io commented Aug 1, 2017

When I upload a new avatar via http://127.0.0.1:8000/avatar/change/ it uploads successfully, however the resized images are not created and so the avatar images are not displayed.

The avatar image is uploaded to /media/avatars/paul/flame_350_vknNF9f.png

It's linking to /media/avatars/paul/resized/80/flame_350_vknNF9f.png and so returns a 404

The 'resized' and '80' directories do not exist.

I don't get any kind of traceback. This is what I get in the terminal:
Not Found: /media/avatars/paul/resized/80/flame_350_bGtZsFN.png
[01/Aug/2017 05:32:54] "GET /media/avatars/paul/resized/80/flame_350_bGtZsFN.png HTTP/1.1" 404 1880

I'm using python 3.5.3, Django 1.11.3, django-avatar 4.0.0, Pillow 4.2.1, ubuntu 17.04

@digitalhurricane-io
Copy link
Author

Looks like I'm getting an IOerror in the create_thumbnail() function in models.py

I had to add a print statement to be sure. It doesn't alert the user in any way when it happens. just returns.
except IOError:
print('IOError')
return # What should we do here? Render a "sorry, didn't work" img?

I'll update after more testing.

@digitalhurricane-io
Copy link
Author

digitalhurricane-io commented Aug 1, 2017

OK. Figured it out.
Things have changed a bit in recent versions of Pillow.

Therefore, if you try to upload a png and AVATAR_THUMB_FORMAT is set to 'JPEG', the image upload will fail silently with an IOError: cannot write mode RGBA as JPEG

If the AVATAR_THUMB_FORMAT is set to 'PNG' everythings fine.

Here is a link to the Pillow issue that helped me out with this. python-pillow/Pillow#2609

The alpha channel must first be removed to save the png as jpeg like so:
image = image.convert("RGB")

The create_thumbnail() function in models.py will need to be edited to fix this

@lggwettmann
Copy link

Does that mean I have to decide if my users should upload jpg or png images? That would be inconvenient. I'm experiencing the same issues. But I'm generally using jpg - and the pngs are not created.

@lggwettmann
Copy link

I'm running django-avatar 4.1.0

@shaneficorilli
Copy link

Any update on this? Are we forced to make users choose one type of image format out of the box? Experiencing the same issue with 4.1.0

@grantmcconnaughey
Copy link
Contributor

@Lone1567 I think we're just waiting for a PR on this one.

@grking8
Copy link

grking8 commented Mar 25, 2019

submitted PR #180

@ntoll
Copy link
Member

ntoll commented Feb 15, 2020

I just encountered this problem too.

@sergioisidoro
Copy link

sergioisidoro commented Apr 27, 2022

Also encountered this issue. AVATAR_THUMB_FORMAT = "PNG" fixed the issue

This project seems to be quite low on maintenance, with last merge being on 2020.
I wonder if it would be a candidate for https://github.com/jazzband , since other great Django projects are also harboured there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants