Home Forums ACF PRO Create multiple images from one ACF upload


Create multiple images from one ACF upload

  • Hey
    Uploading an image, via ACF as usual, but I need to create multiple sized versions of that same image.
    I could just use the regular add_image_size but, this means any other image uploaded, also gets created at these sizes which is not what I want (there will be around 100+ post_thumbnails created each time).

    So, my question:
    Using ACF to upload an image, how would I then create multiple sized copies of that image?

  • If you do not want to use add_image_size() for all the image sizes you need then what you need to do is create an acf/save_post filter. In this filter you would use a combination of WP functions.

    $imagedata = wp_get_attachment_metadata($attachment_id); to get all of the existing metadata

    $resized = image_make_intermediate_size(get_attached_file($attachment_id), $width, $height, $crop); to have WP create the new image size

    $imagedata['sizes'][$name] = $resized; to append your new size with your new name to the metadata

    and then update the metadata wp_update_attachment_metadata($attachment_id, $imagedata);

  • Thanks for replying me.

  • I should add that, if you use any plugin that automatically rebuilds thumbnails your custom image sized created in this manner will be deleted from the image metadata.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.