0

Creating an image gallery. Using WP for image upload & management. Pictures will be uploaded of various file sizes and pixel dimensions. Page load time and SEO are negatively affected by loading large files.

Question: When does WP resize uploaded images? Is it only on display / output?

If so, that means the browser needs to fetch the original, large, slow image and then condense it before serving it to the viewer. Obviously this is bad.

If the above is true, is there a way (without a plugin) to resize an image on upload to a standardized size (say 320x240). Trying to avoid 3rd party (Photoshop, etc) software.

2

WordPress resizes the image when you upload it. By default it provides 4 sizes of your image (providing your image is bigger than the 'large' size).

the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) the_post_thumbnail('full'); // Original image resolution (unmodified)

Source: https://codex.wordpress.org/Post_Thumbnails

You can use the add_image_size() function to specify your own sized images like this:

add_image_size( 'wpse-custom-size', 320, 340);

If there's a chance you might be receiving images of all different sizes and proportions then you may want to crop the image when it's resized. You can do this by providing true as the last argument.

add_image_size( 'wpse-custom-size', 320, 340, true);

Once you have done that, all images that you upload (it won't change the ones that have already been uploaded) will now be available at that size using:

the_post_thumbnail('wpse-custom-size');

Hope that helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.