Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named sizes for 'preview_size' break preview images before page reload #844

Closed
Cai333 opened this issue Jan 23, 2017 · 1 comment
Closed
Labels

Comments

@Cai333
Copy link
Contributor

Cai333 commented Jan 23, 2017

Expected Behavior:

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):

screenshot 2017-01-22 20 25 33

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):

screenshot 2017-01-22 20 30 39

The offending code is in CMB2_Type_File_List.php line 28 and CMB2_Type_File.php line 31:

'data-previewsize' => is_array( $img_size ) ? '[' . implode( ',', $img_size ) . ']' : 350,

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.

@Cai333
Copy link
Contributor Author

Cai333 commented Jan 23, 2017

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.

Cai333 added a commit to Cai333/CMB2 that referenced this issue Jan 27, 2017
…' 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’.

Fixes CMB2#844
jtsternberg added a commit that referenced this issue Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants