Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If I update an image file which had image dimage dimensions of 1:1 and replace it with one of 4:3 the image dimensions did not get updated. It will be displayed at 1:1 (at least with image styles).
The values in the db field_data_field_image > field_image_width and field_image_height are not changed either.
This results in "stretched" images.
Comment | File | Size | Author |
---|---|---|---|
#11 | 2211937-post-commit-fix.patch | 888 bytes | garphy |
#6 | update-image-dimensions-2211937-3.patch | 1.12 KB | Devin Carlson |
#3 | update-image-dimensions-2211937-3.patch | 778 bytes | Devin Carlson |
Comments
Comment #1
grossmann CreditAttribution: grossmann commentedAs I found out this is fixed if I use the media file selector widget (an not the image widget) and just resave the node.
So this may be a bug not related to file_entity.
Comment #2
redndahead CreditAttribution: redndahead commentedWe saw this while studying the code for something else.
This is because in file_entity_file_update there is this if statement.
Which is always false because it's comparing the same variable against itself. Which of course means this will always be the same. So it needs to compare to the old file.
Comment #3
Devin Carlson CreditAttribution: Devin Carlson commented@redndahead Nice find!
A patch to compare the current entity's metadata vs. the original entity's metadata.
Comment #4
Dave ReidI wonder if we should check $file->filesize and $file->original->filesize as well, in cases where the user uploads a different image with the same dimensions?
Comment #6
Devin Carlson CreditAttribution: Devin Carlson commentedAdded an additional filesize check.
Comment #7
Dave ReidLooks great. I think we should file a follow-up to actually set a $file->is_changed property on hook_file_presave() by using a helper method that contains our logic we're putting in here. It could have an alter hook to let other modules figure out if it should be marked as a 'changed' file too.
Comment #9
Dave ReidCommitted to 7.x-2.x and added a follow-up issue: #2350427: Add a helper method to determine if a file has changed
Comment #10
garphy CreditAttribution: garphy commentedI just came accross a case where $file->metadata and $file->original->metadata are not set in file_entity_file_update()
The introduced += statements break with a fatal error.
I don't know if my database is somewhat "not valid" by not having metadata on some file entities, but we should take care somehow.
New issue or new patch in this issue ?
Comment #11
garphy CreditAttribution: garphy commentedHere is what I think we should add to protect the code.
Comment #13
garphy CreditAttribution: garphy at ICI LA LUNE commentedRe-opening since we got no answer from the maintainers on #10 & #11.
Comment #14
Dave ReidLooking at http://cgit.drupalcode.org/file_entity/tree/file_entity.file.inc#n168, I do not see how $file->metadata could not be defined, unless for some reason a complete file object is not being used, not from file_load().
Comment #15
Dave Reid