You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Images added to a file or file_list field should show a preview at the correct size (specified with preview_size).
Actual Behavior:
Regardless of the preview_size set, the preview image (that is initially added to the page via JS) is actually the full size image (the image shown after reloading the page is correct, the issue is only with the JS added image from the media window).
If preview_size is set as an array of height/width values then the full size image is resized to the correct size (resulting in squashed images):
If preview_size is set to a named size (e.g. thumbnail) then the added full size image is resized to a default of 50 x 50 px (for a file_list field) or 350 x 350 px (for a file field):
The offending code is in CMB2_Type_File_List.php line 28 and CMB2_Type_File.php line 31:
I'm currently testing a fix for this which works for the default named sizes ('thumbnail', 'medium', 'large', 'full-size'), but doesn't work for custom defined sizes (with add_image_size( 'custom-size' ... );) although behaviour with custom sizes would be the same as the current.
…' fields
In CMB2_Type_File[_List].php – try to get the closest named image size
from the ‘preview_size’ array and get the correct width and height from
the named size. Pass the named size string as well as the dimensions to
the hidden field to be used by the JS media uploader.
In cmb2.js we can then retrieve the correct image (url and dimensions)
form the returned JS attachment object. Added logic to fit the image to
the preview size rather than stretching the image.
Updated the default preview sizes from the hardcoded 350x350px and
50x50px to ‘large’ and ‘thumbnail’.
FixesCMB2#844
Expected Behavior:
Images added to a
file
orfile_list
field should show a preview at the correct size (specified withpreview_size
).Actual Behavior:
Regardless of the
preview_size
set, the preview image (that is initially added to the page via JS) is actually the full size image (the image shown after reloading the page is correct, the issue is only with the JS added image from the media window).If
preview_size
is set as an array of height/width values then the full size image is resized to the correct size (resulting in squashed images):If
preview_size
is set to a named size (e.g.thumbnail
) then the added full size image is resized to a default of 50 x 50 px (for afile_list
field) or 350 x 350 px (for afile
field):The offending code is in CMB2_Type_File_List.php line 28 and CMB2_Type_File.php line 31:
The numbers are hardcoded again in cmb2.js lines 223–224 and 265, but they shouldn't be an issue if the correct sizes are passed from the field.
The text was updated successfully, but these errors were encountered: