Xử lý ảnh, image trong wordpress full phần 1(ok)

1. Disable image scaling in WordPress (a version 5.3 update)

add_filter( 'big_image_size_threshold', '__return_false' );
i
// https://stackoverflow.com/questions/62996135/remove-scaled-from-automatically-scaled-image-wordpress

Kết quả

Câu hỏi đặt ra có cách nào thay đổi bằng kích thước ảnh gốc không để tôi xóa kích thước ảnh 150x150 đi cho đỡ tốn bộ nhớ :)

Muốn nghiên cứu rõ hơn thì chúng ta tìm hiểu ở file

C:\xampp\htdocs\wordpress3\wp-includes\media.php

C:\xampp\htdocs\wordpress3\wp-admin\includes\image.php

2. Muốn loại bỏ kích thước ['medium', 'medium_large','thumbnail','large', '1536x1536', '2048x2048'] trong wordpress

add_filter( 'big_image_size_threshold', '__return_false' );
add_filter( 'intermediate_image_sizes', 'remove_default_img_sizes', 10, 1);
function remove_default_img_sizes( $sizes ) {
  $targets = ['medium', 'medium_large','thumbnail','large', '1536x1536', '2048x2048','woocommerce_thumbnail','woocommerce_single','woocommerce_gallery_thumbnail','shop_catalog','shop_single','shop_thumbnail'];
  foreach($sizes as $size_index=>$size) {
    if(in_array($size, $targets)) {
      unset($sizes[$size_index]);
    }
  }
  return $sizes;
}

Hướng dẫn cách lấy tất cả các kích thước ảnh đang sử dụng trên website :(

3. Xử lý ảnh kết hợp với lệnh cmd hỗ trợ của wordpress để loại bỏ nhưng kích thước không mong muốn :))

4. My default media setting in WordPress blog is 150x150, 300x300, 1024x1024 respectively for thumbnail, medium, large images. Now I am designing a theme that need different size thumbnail images to show in theme. For this, I go to the media setting again and changed the setting with my news sizes like 72x72, 250x250, 400x400 respectively for thumbnail, medium, large images.

But now to resize my old uploaded images, I used Regenerate Thumbnails WordPress plugin and that generated my new media setting images size easily. So this solved my main problem.

5. Cách sử dụng remove_image_size kết hợp với init cũng có tác dụng như trên :)

function remove_extra_image_sizes() {
  foreach ( get_intermediate_image_sizes() as $size ) {
    if ( !in_array( $size, array( 'medium', 'medium_large', 'large' ) ) ) {
      remove_image_size( $size );
    }
  }
}
add_action('init', 'remove_extra_image_sizes');

Kết hơp với cầu lệnh C:\xampp\htdocs\wordpress3>wp media regenerate --yes

wp media regenerate --yes

Last updated