关于 php:在 WordPress 上将缩略图裁剪为中等大小的精确尺寸 | 珊瑚贝

Crop thumbnail to exact dimensions on WordPress for medium size


在 WordPress 媒体设置中,我们可以将缩略图大小裁剪为精确的尺寸。

但是对于 Medium size 没有获得精确尺寸的选项。有没有办法强制中等尺寸的精确尺寸?

如果是,如何实现到functions.php


如果您希望中等图像被裁剪而不是缩放,例如您可以在选项页面中选择缩略图大小(但不适用于中等或大尺寸),您可以将 medium_crop 选项设置为 true你的 functions.php:

1
2
3
4
5
if(false === get_option(“medium_crop”)) {
    add_option(“medium_crop”,“1”);
} else {
    update_option(“medium_crop”,“1”);
}
  • 我想确定 :-) 请记住,这只会影响未来的图像,但不会影响已经存在的图像。
  • 这绝对是比我更好的解决方案。酷解决方案一月! :)


到目前为止,有更好的方法来做到这一点。您可以使用 add_image_size 函数覆盖默认图像大小(即缩略图、中和大)。

示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// Set”Thumbnail” image size
if( function_exists( ‘add_theme_support’ ) ) {

    add_theme_support( ‘post-thumbnails’ );
    set_post_thumbnail_size( 150, 150, false );

}

// Set”Medium” and”Large” image sizes
if( function_exists( ‘add_image_size’ ) ) {

    add_image_size( ‘medium’, 300, 9999, false );
    add_image_size( ‘large’, 1024, 9999, false );

}


将此添加到您的functions.php:

1
add_action( ‘init’, create_function( , ‘add_image_size(“cropped_medium”, 300, 150, true );’ ) );

参数是大小名称、宽度、高度以及是否强制裁剪。

  • 解析错误:语法错误,第 77 行 /functions.php 中的意外 T_STRING
  • John 忘记了 ‘init’ 和 create_function 之间的逗号。


来源:https://www.codenong.com/3454337/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8907.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?