亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Wordpress 自定義圖像大小 upcsacle image

Wordpress 自定義圖像大小 upcsacle image

PHP
人到中年有點甜 2022-12-03 11:06:56
我建立了一個自定義 wordpress 網站并添加了一些自定義圖像大小。問題是當用戶上傳較小的圖像 (700x300) 時。比圖像不裁剪以適應自定義寬高比。如何放大圖像以適合我的裁剪尺寸(1:1 縱橫比)?這是我的作物功能:add_image_size( 'article-crop', 700, 700, true );
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

可以通過將此代碼添加到主題的 functions.php 文件來修復它。它放大圖像以適合所有縮略圖大小并正確裁剪它們。


/*  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 );

資源


查看完整回答
反對 回復 2022-12-03
  • 1 回答
  • 0 關注
  • 111 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號