3

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

3
  • 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
    Commented Aug 22, 2011 at 17:31
  • Hey Tom, yeah that works, but kinda defies the point of people uploading the correctly sized images. Commented Aug 22, 2011 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
    Commented Aug 22, 2011 at 17:46

2 Answers 2

7
+25

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.

3
  • 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. Commented Aug 22, 2011 at 22:16
  • Should of updated this years ago. For anyone else getting varying sizes check you functions.php file to see if the $content_width variable correlates to your design / media settings. This was causing issues in my case. Commented Jun 16, 2014 at 18:41
  • Sp many times a client will upload a correctly sized image, so a resized image is not generated, but they took a PNG screenshot and it's now a 3mb file. Would be nice if we could force a JPG to always be made at the right compression.
    – Drew Baker
    Commented Dec 18, 2015 at 6:15
1

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');
}
1
  • Hmm thanks for the suggestion Mike but unfortunately the large image returns the medium image. Commented Jul 1, 2011 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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