Replacing image with cropped version causes srcset references getting outdated
-
Scenario
- Created an Image Slider with Gutenslider.
- Each image in the slider gets its
srcset
markup. I assume it uses WP’s default “Responsive Image” mechanism. - Sometimes later I decided to crop the images in the series a bit further so that more of them gets readable.
- I cropped them on my computer with my image software.
- Media Library → List Image → Identify Image of my series → “Replace Image” (this action comes from your plugin) → Replaced it with the cropped image version on my computer. Did this for all 5 images in the slider.
? After that: All images showed as broken (only their ALT text)
- Reason: The
srcset
references were not updated and hence all point to files which don’t exist anymore! - Because in the new
srcset
of the corresponding image files the-XXXxYYY
suffix part changed due to the slightly different aspect ratios of the cropped images. (e.g. 1024×796 became 1024×838).
?? Proposal: When the plugin replaces an image it also updates the
srcset
accordingly in all existing markup. This should be easily possible without doubt, as in well-formed markup the mainsrc
attribute of the image is the same unchanged URL and also in theclass
attribute it has the unique media library identifierwp-image-1234.
?? If this is not possible then the minimal improvement would be to compare the old vs the new image dimensions and give a warning to the user that updating an image with an image of different proportions,
- may result in layout issues if not having used percentual/responsive image layout techniques (lesser problem)
- and will certainly result in srcset file references to break which will render various blocks to have broken images! You will need to re-create image markup (the very task which you wanted to spare yourself by using the plugin).
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Replacing image with cropped version causes srcset references getting outdated’ is closed to new replies.