1

I am using ACF to pull images using ‘wp_get_attachment_image_src’ as such:

<?php $image = wp_get_attachment_image_src(get_field('image'), 'large'); ?>
<img src="<?php echo $image[0]; ?>" alt="" />

Whatever image size I enter (here it is ‘large’, but it could be a custom image size), if the image that has been uploaded was smaller than the set size, that size will not have been created and Wordpress will use the full, original, uncompressed image as a fallback.

This is very undesirable, as the image will often have no compression and be a very large filesize unnecessarily.

What are the workarounds for this? Can I make Wordpress create a full pixel-size, yet jpeg compressed image and make it use that as the fallback?

Thanks in advance for your help!

1
  • 1
    Could we build some sort of conditional using:[3] => boolean: true if $url is a resized image, false if it is the original.
    – Jacob
    Jan 7, 2014 at 21:24

1 Answer 1

0

wp_get_attachment_image_src the SIZE parameter will return image closest to the given.

If you want to return cropped image you can register your own sizes with add_image_size() function.

After you register your sizes you have to regenerate all old Images otherwise the old images will not have the new size.

You can do that with "Regenerate Thumbnails" plugin

1
  • Thank you for your help, I am aware of the steps you outlined. My problem is that Wordpress always falls back on the "full", original uncompressed image, not the closest-size compressed one. Is there a way of forcing it to fall back on a compressed image rather than the untouched original?
    – Jacob
    Jan 7, 2014 at 21:44

Your Answer

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

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