简体   繁体   中英

Wordpress image resize on upload

I have wordpress plugin which has widget where users can upload their image. For uploading image I am using wordpress built in functions for media included by:

wp_enqueue_media();

Which gives me the same UI for uploading image from my widget like it's under Media tab.

I also added my custom size of the image to be created on upload:

add_image_size( 'my_size', 360, 540, false );

And I am using this size of the image to display it on the frontend. The problem is that, when wordpress resize original image to this size it loose quality. The image "my_size" is like blurred.

Does anyone have some idea how this can be resolved. To keep image quality when it's resized, or at least to not loose too much on the quality.

By default WordPress reduces the image quality of an image to reduce its size. If you don't want this to happen you can use a filter you customize the quality at which the image is saved. The default WordPress quality was 90%, and from WordPress 4.5 on was decreased to 82%.

You can use the filter below to modify the quality to 100% is this is what you need.

add_filter( 'jpeg_quality', 'image_quality');

function image_quality() {
    return 100;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM