Hi guys,
I have an image field which I use to generate automatic post-specific page headers in the GeneratePress theme. It works quite well with Toolset Content Templates.
But I must create scrset sizes of the header image, for performance reasons.
[wpv-post-featured-image size="full"] creates correct srcset markup on its own, but this is not the case with image fields.
So, I followed Nigel's instructions from this thread:
https://toolset.com/forums/topic/image-srcset/
Unfortunately, in practice it doesn't work as expected, because the versions resized by Toolset are not proportional.
For example, my media library size for large is: max-width: 600px, max-height: 400px.
When I insert images into posts normally through the library, or using [wpv-post-featured-image size="full"], the srcset sizes will have the correct aspect ratio. For example size-large for an image with an aspect ratio 16:9 will be 600x338 and not 600x400. It is max-width and max-height, and not exact dimensions.
But it seems that Toolset doesn't respect the aspect ratios and crops to exact dimensions.
Let's say my page headers have an aspect ratio of 4:1. But Toolset will crop the srcset sizes to 3:2 (large will be exactly 600x400 - but it should be 600x150px).
[types field='some-image' size='large' url='true'][/types]
will create a path like this:
./wp-content/uploads/2019/08/some-image-file-wpcf_600x400.jpg
And it is obviously different from the resized versions created by the media library.
And it means the srcset is not usable with Toolset image fields.
If I insert the same image into post through WP Media Library, the srcset sizes will have the correct aspect ratio. So, it seems like a bug in the Toolset image field. The problem doesn't exist for the featured image shortcode, though.
Ideally, there would be an option to insert full srcset markup through the image field (somehow WordPress can do it very well for normal images). But I would be happy if I could at least generate proportional thumbnails, large, medium through the image field...
Cheers,
Tom