<?php
function multi_trim_dimensions( $first, $orig_w, $orig_h, $dest_w, $dest_h, $crop ){
if( false ) return $first;
if( $crop ) {
$start_x = floor( $dest_w / 10000 );
$start_y = floor( $dest_h / 10000 );
$new_w = $dest_w % 10000;
$new_h = $dest_h % 10000;
$trim_w = $new_w;
$trim_h = $new_h;
} else {
$trim_w = $orig_w;
$trim_h = $orig_h;
$start_x = 0;
$start_y = 0;
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
}
if ( $new_w >= $orig_w && $new_h >= $orig_h )
return false;
return array( 0, 0, (int) $start_x, (int) $start_y, (int) $new_w, (int) $new_h, (int) $trim_w, (int) $trim_h );
}
add_filter( 'image_resize_dimensions', 'multitrim_dimensions', 10, 6 );
if ( function_exists( 'add_image_size' ) ) {
//上四桁開始点 下四桁生成サイズ
add_image_size( 'mini', 00000320, 00000240, true );//左上を開始点として横360px縦240pxのサイズでトリミング
add_image_size( 'icon', 05000032, 02000032, true );//左上から横501px縦201pxの位置を開始点として横縦32pxでトリミング
}
?>
!!!ご注意ください!!!コレを使用することによって、通常のリサイズトリミングが出来なくなります。
使用に起因する一切の責任は負いかねます。自己責任でご利用下さい。
wordperssで、1つの画像をUpしただけで、色んな場所から色んなサイズでトリミングしたいなと思って作りました。
wordperssのサムネイル処理をまるごと書き換えるカタチになります。
functions.phpに追記したら使えると思います。
add_theme_supportとか記述済み前提です。