Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So if I set the large image size in the media library to say 600x600 pixels, and then upload an image which is the same dimensions it won't get set as the 'large' image.

There is talk on this question about it being the ratio, but I don't think this is the case. Also I don't want to setup another custom image size as its will just bloat the server with redundant images, when 'large' should work!

Is there a filter or setting where I can change the logic of the images, so if the dimension is larger than , OR equal to the media library setting it gets set as the large image. At the moment the equal to seems to be missing.

Thanks

share|improve this question
1  
We've noticed that an image has to be slightly larger than the target in order to be resized down, what happens if you upload a 605x605 image? –  Tom Aug 22 '11 at 17:31
    
Hey Tom, yeah that works, but kinda defies the point of people uploading the correctly sized images. –  addedlovely Aug 22 '11 at 17:42
    
True :) I always assumed this was a bug in core somewhere, since it appeared that WP didn't generate the larger size image on disk. We just supplied the image sizes with an additional 5px either size. Might be worth checking core.trac.wordpress.org for any reference to it. –  Tom Aug 22 '11 at 17:46
add comment

2 Answers

Maybe this would do the trick. If your full image has the same dimensions as your large settings (and thus is set as 'full'), show the full image instead of the large one :

if( empty( get_the_post_thumbnail( $post->ID, 'large') ) && !empty( get_the_post_thumbnail( $post->ID, 'full') {
    // show full image (same size as large)
    echo get_the_post_thumbnail( $post->ID, 'full');
} else {
    // show large image
    echo get_the_post_thumbnail( $post->ID, 'large');
}
share|improve this answer
    
Hmm thanks for the suggestion Mike but unfortunately the large image returns the medium image. –  addedlovely Jul 1 '11 at 15:52
add comment

No, it won't create a new image that is exactly the same size.. nor should it. All the thumbnail, medium, and large images are resized images, by definition. Since the original image is already 600x600, there's no point in creating another file at the same size, but with a lower quality (remember that JPEG compression is lossy).

However, if you specify in the template call that you want to use the large image size with something like <?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>, and there is no "large" size available for that image, then it will actually use the full sized image, not the medium sized one. It always chooses "up", basically.

See, whenever you specify an image size like large or medium or even array(400,400), then what WordPress does is to pick the next larger size image that it can find and then it uses that, along with width/height rules in the IMG tag to make the browser resize it down. It does this because images look like crap when sized up, but reasonably okay when sized down.

So yes, even without the large image size being created, specifying the "large" size as a size in the template is okay and will work correctly. I've just tested this on a test site, using this exact code and sizing, and it works properly. Specifying the large size made it actually use the URL of the full size, not the medium one.

share|improve this answer
    
Hey Otto, thanks for the reply. I don't expect Wordpress to generate a redundant thumbnail, just mark the image into the appropriate size category, so its large, and also fullsize. I'll see if I can throw a test case together, your logic makes sense, but in practise I'm sure I get varying results. –  addedlovely Aug 22 '11 at 22:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.