the_post_thumbnail hard cropping not working no matter what

No matter what I do – I can’t get the hard cropping mode in the_post_thumbnail to work.

Here’s what I have:

Read More
add_image_size( 'Blog', 300, 300, true ); 
the_post_thumbnail('Blog');

I’ve also tried:

set_post_thumbnail_size( 300, 300, true );
the_post_thumbnail();

I’ve tried uploading new images, and using the “Regenerate Thumbnails” plugin, but still no luck. It completely ignores the “true”, and acts as if it’s “false”. For example, instead of the image being 300×300, it’ll be 300×238 or something.

Has anyone else experienced this? My GD Library is enabled..

Thanks for any input anyone can offer =)

Related posts

Leave a Reply

8 comments

  1. I would say that you might not have the GD libraries installed on your server. Without this, you will only get the file uploads and no image crops.

    First, do a sanity check by calling phpinfo() to see if GD is installed.

    GD Installation on Linux

    If you have shell access, simply type this command:

    sudo apt-get install php5-gd
    

    You’ll need to restart the server after installing GD

    Here’s the command to reboot Apache:

    /etc/init.d/apache2 restart
    

    Shared Hosting

    If you’re on a shared box, you’ll need to contact your host and have them install it on your server.

    One Last Thing

    Does your theme have thumbnail support?

    add_theme_support('post-thumbnails');
    
  2. I’ve actually finally fixed this issue.

    It seems that the hard-cropping works if you set the image size inside a function that is hooked into the “after_setup_theme” hook.

    So, the below would work:

    function add_custom_sizes() {
        add_image_size( 'portfolio-thumb', 243, 163, true );
        add_image_size( 'portfolio-image', 1074, 725, true );
        add_image_size( 'available-homes', 500, 279, true );
        add_image_size( 'idea-thumb', 146, 141, true );
    }
    add_action('after_setup_theme','add_custom_sizes');
    

    This will allow you to get actual hard cropped images using the sizes specified using the_post_thumbnail().

    Hope this helps someone else as well.

  3. Instead of defining the post thumbnail size as blog why not just set the post thumbnail explicitly in the template where you want it to show up…

    the_post_thumbnail($post->ID, array(300,300, true));
    
  4. I’ve just had this same issue and the answer for me was regenerating thumbnails as bryceadams suggested (I don’t have enough points to vote for his response unfortunately).

    Caveat: The images must be stored locally not remotely. Presumably no thumbnails are generated for remote images.

  5. In my case, this issue was caused by filer permissions on the images. I had copied the images from one server to another, forgetting to change the ownership. When new image sizes were set, and I regenerated them, the old images weren’t overwritten as they should have been.

    To fix this I connected to my server with SSH, navigated to the wp-content/uploads folder and reset the ownership of all the images there. e.g.

    chown -R {web user}:{group} .
    

    Hope that helps someone.

  6. You’ll never have a hard-cropped image other than the default sizes.
    You’ll not get this answer in WP forums, or if you do, they’ll show you a carrot for weeks until you get anxious and get blocked or they fixed it silently.

    The hard-cropped images are only for

    • Thumbnail
    • All other sizes EXCEPT thumbnail AND YOUR CUSTOM SIZES

    Things that are not possible are NEVER shown in the front end or tried to be covered up in forums as much as possible (our free .org project is their .com product) even if the above options got you pulling your hair for months.

    The second option should read “ALL OTHER SIZES EXCEPT YOURS”

    I’m developing a plugin for that, and an extra magic. I’ll get it done soon, but I’ll need some help to publish it in the plugins library since I’ve been banned! hehe (for helping others with un-reported (or ignored) bugs)

  7. I had the same issue and installed a plugin that allows to regenerate one/some/all of your images. This is the plugin: [http://wordpress.org/plugins/regenerate-thumbnails/]

    I did not find the way of doing it from the WP admin UI except if you delete and upload the image again.

    Another way of doing it, if you do not want to use a plugin, would be to do it with PHP functions

    function wp_regenerate() {
    include( ABSPATH . 'wp-admin/includes/image.php' );
    wp_generate_attachment_metadata( $thumbnail_id, $absolute_path_to_image ); }
    
    add_action('after_setup_theme', 'wp_regenerate');
    

    where $thumbnail_id and $absolute_path_to_image have to be set with the values you want.

    Thanks to @briceadams and @adriaticiq. I cannot yet vote you but I will as soon as I am allowed.