Support » Plugins and Hacks » Hacks » [Resolved] the_post_thumbnail & add_image_size bug

[Resolved] the_post_thumbnail & add_image_size bug

  • Where to begin.. I recently moved my blog over from shared hosting (ipower) to Amazon EC2. I’m loving the control that EC2 offers, but I’ve definitely had to deal with my share of bugs from the migration. Most of them I’ve been able to resolve, but this one is tough. The post thumbnails are the wrong size. This functionality works fine on the old site but is completely broken on the new site. Consider this example:


    <div class="thumb shadow_600"><a href="http://oldsite.MYDOMAIN.com/dev/?p=4"><span></span><img width="600" height="250" src="http://oldsite.MYDOMAIN.com/dev/wp-content/uploads/2013/03/styleofeye11-600x250.jpg" class="fadeover wp-post-image" alt="styleofeye1" title="test" /></a></div>
            <br class="clear" />


    <div class="thumb shadow_600"><a href="http://MYDOMAIN.com/dev/?p=9"><span></span><img width="428" height="250" src="http://MYDOMAIN.com/dev/wp-content/uploads/2013/03/styleofeye1.jpg" class="fadeover wp-post-image" alt="styleofeye1" title="test" /></a></div>       
            <br class="clear" />

    Notice how the width of the image is off on the new site.


    if ( function_exists( 'add_theme_support' ) ) {
    	add_theme_support( 'post-thumbnails' );
        set_post_thumbnail_size( 200, 200, true);
    if ( function_exists( 'add_image_size' ) ) {
        add_image_size('big_size', 920, 360, true);
        add_image_size('single_size', 600, 350, true);
        add_image_size('blog_size', 600, 250, true);
        add_image_size('half_size', 600, 250, true);
        add_image_size('medium_size', 280, 160, true);
        add_image_size('small_size', 200, 150, true);
        add_image_size('square_size', 183, 183, true);

    homepage-blog1.php (snippet that adds the thumbnail image)

    <?php if($image) { ?><div class="thumb shadow_600"><a href="<?php the_permalink();?>"><span></span><?php $attr = array('class' => "fadeover", 'title' => get_the_title() ); the_post_thumbnail('blog_size',$attr);?></a></div><?php } ?>

    I am totally at a lost. I am running the latest version of WordPress (3.5) on both servers. Any ideas? Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • For some reason, the system cannot find the proper reduced image so it is using the original image and letting the browser scale it. (It does exist, right?) How it finds the right sized image is an elaborate process, so it’s impossible to say where a likely failure point is.

    To find the cause of this issue, you’re going to have to trace into the_post_thumbnail() function, temporarily inserting var_dump($useful_var); wp_die(); lines at various places until you zero in on the problem. Of course, you replace $useful_var with an appropriate variable you wish to investigate. You’ll find yourself drilling down into several sub-functions, so I’ll give you a hint. The fault probably lies in image_get_intermediate_size(), several layers down.

    There’s still a lot of code to check there, I hope it’s not too hard to find the fault, good luck.

    Hey bcworkz. Thanks for the information. I did some more investigating today and noticed that the issue wasn’t that the theme wasn’t grabbing the correct images from the uploads folder, it’s that the images it needs don’t exist.

    The images actually weren’t being cropped. A simple Google search revealed that WordPress is dependent on the php-gd library. I installed this on my server and restarted Apache. Then, I re-uploaded the featured images and it worked perfectly.

    I had the idea something like that could be the case only after typing my response, leading to the addition of “(It does exist, right?)”

    There is a distinct lack of information about required modules in the Codex. I don’t suppose you stumbled on a list of such modules anywhere in your searching? This would be useful info to many.

    This post does a really good job of identifying all necessary libraries:


    Thank you, that is very useful. I’m not quite sure how distill that into a good authoritative Codex entry, (which may be why it does not exist there) but I intend to try.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] the_post_thumbnail & add_image_size bug’ is closed to new replies.
Skip to toolbar