Currently, file_validate_image_resolution does not allow you to not resize the image when you don't want to. Sometimes, this can be useful when you want a specific resolution, and you don't want anything greater in any circumstance. This can easily be fixed with an additional parameter and a conditional. Patch coming in a few minutes.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 353580-11-axyjo.patch | 5.17 KB | axyjo |
| #9 | 353580-9-axyjo.patch | 3.84 KB | axyjo |
| #5 | 353580-5-axyjo.patch | 4.66 KB | axyjo |
| #2 | 353580-2-axyjo.patch | 2.12 KB | dawehner |
| #1 | 353580-1-axyjo.patch | 1.83 KB | axyjo |
Comments
Comment #1
axyjo commentedHere's the patch. The $maximum_resolution parameter has something about resizing, but it's totally unclear (at least for me).
Comment #2
dawehnerTRUE should be used instead of true
i like the idea, because its not always needed to resize the picture
perhaps it would be possible to add a test for it
Comment #3
drewish commentedI'd actually suggest splitting it into two separate functions. One that just reports an error and the other that resizes. That's based on the feedback we got for the Guess what the File API functions do! quiz. The name file_validate_image_resolution doesn't imply that it'll be doing resizing.
Comment #4
drewish commentedalso you'll definitely need to add test coverage before this could be committed.
Comment #5
axyjo commentedAdded (some) test coverage.
Separated resizing and resolution pars, as per #3.
Also fixed a bug where if $resize was FALSE, $errors[] would not get populated.
Comment #6
drewish commentedthe function names should be rethought. there's not a clear separation between them and they're badly named. one function should just enforce the sizing requirements and the other should just resize images and only report errors if there's a problem. i don't think $resize should be an option. if you don't want resizing you don't use the resize validator.
Comment #7
axyjo commentedChanging the function names will break modules that use it, or is that OK since D7 isn't being released for a few months? I'll try and catch all of the functions and rename them as well.
Comment #8
drewish commentedYeah you'd need to update the modules that use the validators. We don't worry about breaking compatibility between major versions of Drupal.
Comment #9
axyjo commentedHere's a patch. It updates the tests, but it doesn't update modules.
Comment #10
drewish commentedmaybe file_validate_image_force_maxsize() ? would be a better name since it only scales down large images?
Comment #11
axyjo commentedYeah, that's true. Agreed.
Comment #12
drewish commentedHumm... I've been giving this some more thought and I think we need to split the functions that just read a file from those that modify it and have them applied in two passes. The problem is that you want to reject an invalid file before copying it into Drupal's files directory but the modifiers can't make changes to a file until it's been moved from the temp directory into drupal's files directory. So it seems like it needs to be validation that occurs before move_uploaded_file() is called and then modification happens once it's in the files directory.
Comment #13
axyjo commentedWon't file_save() save the modified file when it's resized though?
Comment #14
drewish commentedI mean the actual modifications to the file on the disk. Certain server configurations prevent PHP from making changes to files in the temp directory. The need to be moved under Drupal's root directory first.
Comment #15
drewish commentedsee #357469: file_save_upload() fails to handle open_basedir restriction
Comment #16
axyjo commentedA small patch has been made to #357469: file_save_upload() fails to handle open_basedir restriction.