Tracking PR - A conversation starter #10
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our issue: We have many use cases for a given image uploaded into our system. Each use case requires an image of a specific size/aspect ratio. While we could handle the size issue by always sending the largest version of the image and allowing the browser to scale the image down, we'd still suffer from image distortion when the use case requires a change to the aspect ratio. So, at the very least, we would need to create a crop of each image for each unique aspect ratio that exists on our site. Cropping automatically is unreliable (from a quality perspective) so, our users would still need the ability to override a bad crop.
Our Solution: Create simple way, in the Django admin, for users to create a custom crop for each image use case.
Implementation: This feature comes in two parts: a custom django DB field and a custom django form widget.
The DB field maintains the crop (use case) definitions, creates the various image version (by cropping and resizing), and provides a simple way to access image versions from the fieldFile instance returned when image field is accessed.
The form widget handles the creation of the cropper (in the admin) and some of the user input validation. Here is a shot of it in action:
This implementation relies on user provided functions and Django storages to define how to access each image version (just like ImageField does with it's 'upload_to' parameter); so, no additional information is written to the database. A dictionary with accessor methods is added to the standard ImageFieldFile instance which allows access to image versions like this:
Code clean up and tests are forthcoming. In the mean time, I'd like to hear your comments/concerns regarding this feature. Is apps.images the place for this kind of thing? If not, where does it belong?