Créer une miniature plus grande que la taille originale

Il se peut que vous ayez besoin pour un thème de créer des minia­tures plus grandes que les images origi­nales, ce qui n’est pas possible par défaut dans Word­Press. Ce code à insé­rer dans le fichier functions.php de votre thème va déblo­quer le problème.

Source : https://​word​press​.stackex​change​.com/​q​u​e​s​t​i​o​n​s​/​5​0​6​4​9​/​h​o​w​-​t​o​-​s​c​a​l​e​-​u​p​-​f​e​a​t​u​r​e​d​-​p​o​s​t​-​t​h​u​m​b​n​ail

Code

/*  Thumbnail upscale
/* ------------------------------------ */ 
function alx_thumbnail_upscale( $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', 'alx_thumbnail_upscale', 10, 6 );

If you have found a spel­ling error, please, noti­fy us by selec­ting that text and pres­sing Ctrl+Enter.

Ce site embarque des cookies pour vous offrir la meilleur expérience possible

Spelling error report

The following text will be sent to our editors: