ImageField does not set width/height_field using 'actual' file
|Reported by:||vicvicvic||Owned by:|
|Has patch:||yes||Needs documentation:||yes|
|Needs tests:||no||Patch needs improvement:||yes|
As mentioned in django-developers, models.ImageField (actually ImageFieldFile.save) updates width/height_field using the 'original' (typically uploaded) file, not the one that gets saved. This means that if you don't save the same file as the one being uploaded (because you have resized it), width and height are incorrect.
The code to set width/height is in ImageFieldFile.save, and happens before the file is saved.
I'm attaching a patch which moves this code below the save call and uses the final file to find the dimensions. I don't know much about Django internals so it might need polishing, then again, it really just moves some code down a few lines and changes one function call.
Change History (8)
Changed 8 years ago by vicvicvic
comment:1 Changed 8 years ago by Gulopine
- Needs documentation unset
- Needs tests unset
- Owner changed from nobody to Gulopine
- Patch needs improvement unset
- Status changed from new to assigned
comment:4 Changed 8 years ago by jacob
- Component changed from Uncategorized to File uploads/storage
- Triage Stage changed from Unreviewed to Accepted
comment:5 Changed 8 years ago by Gulopine
- Needs documentation set
- Owner Gulopine deleted
- Patch needs improvement set
- Status changed from assigned to new