ネイティブのWordpress image_resize関数を使用して、画像を拡大できます。Wordpressは " image_resize_dimensions " と呼ばれるフックを提供しており、これを使用してデフォルトのトリミング設定を上書きできます。以下は、スケールアップをサポートする変更された関数です。
function image_crop_dimensions($default, $orig_w, $orig_h, $new_w, $new_h, $crop){
if ( !$crop ) return null; // let the wordpress default function handle this
$aspect_ratio = $orig_w / $orig_h;
$size_ratio = max($new_w / $orig_w, $new_h / $orig_h);
$crop_w = round($new_w / $size_ratio);
$crop_h = round($new_h / $size_ratio);
$s_x = floor( ($orig_w - $crop_w) / 2 );
$s_y = floor( ($orig_h - $crop_h) / 2 );
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
}
この関数を次のようにフックします。
add_filter('image_resize_dimensions', 'image_crop_dimensions', 10, 6);
それが完了したら、image_resize関数を使用して、必要に応じて画像を拡大または縮小できます。
$cropped_image = image_resize($image_filepath, $width, $height, true);