For a custom post type I have an image upload/media library field, that adds images as attachments in the post.
While saving the post I am resizing the selected image - to some new non existing images sizes with WP_Image_Editor
.
This is the part of the code, when I generate the new image sizes:
$path = wp_get_original_image_path( $imageObject['ID'] );
$wp_editor = wp_get_image_editor( $path, array() );
$result = $wp_editor->resize($size['max_w'], $size['max_h'], $crop);
if( !is_wp_error( $result ) ) {
$wp_editor->save( $wp_editor->generate_filename() );
}
So, I am saving the new sizes, next to the original and the existing ones.
I am trying to load one of those new image sizes using:
wp_get_attachment_image_src($imageObject['ID'], [$size['max_w'], $size['max_h']]);
Or, I would like to be able to find the new sizes in the sizes element of the image array when I call wp_get_attachment_image($imageObject['ID'])
.
But, I am not able to get that new image size.
Is this possible at all? Am I missing something? (--probably yes)
Do I have to save the new images in a different way? Or do I have to add any additional steps before or after saving, in order to add the new sizes to the image?
And what about naming those new sizes?
And, how about creating a new responsive image with an srcset with these new sizes?
*I am not interested in taking the add_image_size
route.