简体   繁体   中英

Crop thumbnail images - add_image_size - Wordpress

I am trying to add a thumbnail crop to images, however I can't get it to work correctly. I have faced similar problems earlier, but wasn't able to solve it.

The page shows the latest posts, and since some of them has different horatio and size, I must use thumbnail crop within functions to make them appear the same size and correct horatio, and not scale them into something different.

This is the code I am using to show latest thumb

<?php if ( has_post_thumbnail() ) { the_post_thumbnail('frontpage_thumb');  } ?>

Within functions.php:

if ( function_exists( 'add_theme_support' ) ) { 
    add_theme_support( 'post-thumbnails' ); 
    add_theme_support( 'nav-menus' );
}

add_action( 'after_setup_theme', 'mytheme_custom_thumbnail_size' );
function mytheme_custom_thumbnail_size(){
    add_image_size( 'frontpage_thumb', 300, 220, array( 'center', 'center' ) ); // Hard crop center
}

The problem

They thumbs resize, but don't crop. See page.

I have tried Regenerate Thumb Plugin , but no result.

Have I misunderstood the "WP cropping" ?

The problem appeared to be related with the thumbnails with Wordpress.

To solve the problem I did the following:

  • Uninstall the thumbnail plugin used
  • Install another thumbnail plugin
  • Regenerate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM