Php Wordpress缩略图上载多个自定义大小

Php Wordpress缩略图上载多个自定义大小,php,wordpress,resize,Php,Wordpress,Resize,我正在wordpress中开发一个CMS网站。 我的网站模板有多个页面,在这些页面中,我有不同大小的图像。这些图片将是这些帖子的特色图片 比如说在主页上,我有一个特别的div,图像大小应该是720x963 在同一页的特色div下面,我有一个div用于其他帖子,其中图像大小为350 X 224 最后,我有一个页面,我在其中显示了一个特定类别的帖子,比如作为图库的形式,其中图像缩略图的大小是257x161 在所有这些页面中提取的图像就是文章的特色图像 我尝试将functions.php修改为 //

我正在wordpress中开发一个CMS网站。 我的网站模板有多个页面,在这些页面中,我有不同大小的图像。这些图片将是这些帖子的特色图片

比如说在主页上,我有一个特别的div,图像大小应该是720x963

在同一页的特色div下面,我有一个div用于其他帖子,其中图像大小为350 X 224

最后,我有一个页面,我在其中显示了一个特定类别的帖子,比如作为图库的形式,其中图像缩略图的大小是257x161

在所有这些页面中提取的图像就是文章的特色图像

我尝试将
functions.php
修改为

// Set up custom post image sizes
if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'home-post-thumbnail', 350, 224 );
}

// Set up custom post image sizes
if ( function_exists( 'add_image_size' ) ) {
    add_image_size( 'home_featured-post-thumbnail', 720, 963 );
}
在主题中使用它作为

但它不工作。我浏览了
wp content
文件夹,查看调整大小的文件是否可用,但不可用

如何强制wordpress将图像大小调整为所需的精确大小。

尝试以下方法:

$image = wp_get_image_editor( 'cool_image.jpg' ); // Return an implementation that extends <tt>WP_Image_Editor</tt>

if ( ! is_wp_error( $image ) ) {
    $image->rotate( 90 );
    $image->resize( 300, 300, true );
    $image->save( 'new_image.jpg' );
}
$image=wp\u get\u image\u编辑器('cool\u image.jpg');//返回扩展WP_图像编辑器的实现
如果(!is_wp_error($image)){
$image->rotate(90);
$image->resize(300300,true);
$image->save('new_image.jpg');
}

这可能也会引起您的兴趣:

您应该先检查
添加主题\u支持
功能,然后再检查
添加图像\u大小
类似功能

if(function_exists('add_theme_support'))
add_theme_support('post-thumbnails');
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'home-post-thumbnail', 350, 224 ,true);
}

// Set up custom post image sizes
if ( function_exists( 'add_image_size' ) ) {
add_image_size( 'home_featured-post-thumbnail', 720, 963,true );
}
 the_post_thumbnail('home-post-thumbnail');// for automatically crop when uploaded
和检索缩略图

get_the_post_thumbnail($post->ID, 'home_featured-post-thumbnail');  

它在做修剪,但不严格。我的意思是720的高度被裁剪,但是它会自动裁剪宽度。如果我想同时创建150*150和300*300的图像,有没有办法创建多个大小的图像,可以吗?