Even 2560px is too big! ?? How to change the automatic reduction when uploading a huge image to an arbitrary value

Even 2560px is too big! ?? How to change the automatic reduction when uploading a huge image to an arbitrary value

Thank you for visiting. This page is an English translation of the Japanese site [Knowledge Base] using Google Translate. Please understand that there are some points that are difficult to read, such as sentences and expressions.

An automatic reduction function when uploading a huge image added from WordPress version 5.3 (I think it was). If you upload a big and large image as it was taken with a digital camera, many people may be surprised to find the mysterious character string “-scaled” in the file name.

The condition and operation that this “-scaled” is given (automatic reduction is performed) is that when uploading an image, if the larger side (long side) of the width or height exceeds 2560PX, the height and width While maintaining the ratio, the long side is reduced to 2560px and saved.

However, isn’t 2560px big in the first place? Even if the width of a general theme is wide, it will be about 1280px, the minimum width when making it compatible with AMP is 1200px, and even if it is treated as a search engine’s attention article, it was certainly 1280px or more, so the point is that 1280px is enough There no? I think, what about?

Is there a good way to do it right away? Although I investigated, many ways to disable it and make it a lawless zone were introduced, but on the contrary, isn’t it big even at 2560px? I couldn’t find any useful information in my search ability.

I decided to use 1280px myself, so I can’t give up, so if I can’t speak Japanese, it’s worldwide! If you do your best and search in English, it seems that you can implement it with unexpectedly simple code.

If you have experience of adding some code to functions.php of the theme, you can set the standard of the long side of the image to be uploaded in the future to any value just by copying and pasting, so the same idea as mine Please set it by all means.

Naturally, the original image after uploading will be reduced to an arbitrary value, and the image quality will be 90% of the original image by WordPress standard, so please save important images in another place such as a computer.

The code introduced works when uploaded from the post edit screen via the media library, and it is not checked whether it works when uploading images from the front end (bulletin board, contact form, etc.).

Code that reduces the long side of the original image after uploading by an arbitrary value

If you add the following code to the theme’s functions.php, you can limit the long side to 1280px (images over 1280px will be automatically reduced)

/***** Automatically reduce uploaded images to 1280 pixels *****/
/* User-defined */
if ( !function_exists( 'hab_big_image_size_threshold' ) ){
function hab_big_image_size_threshold( $threshold ) {
    return 1280; // new threshold
}
}

/* activation */
add_filter('big_image_size_threshold', 'hab_big_image_size_threshold', 999, 1);	

If you want to set it to something other than 1280px, change 1280 in “return 1280” on the 5th line to any value.

Effect of reducing the size of the original image

By making the original image smaller, the following effects can be obtained.

  1. Save server space
  2. Images of different sizes generated from smaller images will have smaller capacity
  3. By delivering a small capacity image, the transfer amount when displaying the page is reduced and the display speed is increased.

1 is a natural result. Recent servers have a large capacity, so you may not care so much, but if you continue to operate for a long time, it may become a problem later.

2 is to reduce the image (4,352,000 grains in total) composed of 2560×1700 grains (pixels) each having a color etc. to 1280×800 grains (pixels) (1,024,000 grains in total). Since the amount of grains is about 1/4, if you make a small image based on it, it will be physically smaller, and if the element with a larger capacity is scraped when reducing the grains , The theory is that the size of small images created based on it will also be smaller.

3 is based on SEO’s basics of improving display speed = “creating pages that are easier for users to access”, so you can expect better decisions from search engines.

Post Author: