Background
I have a hover effect where two svgs mask to create a hole that the base image can be seen through on tiles of various sizes and dimensions. So far I've managed to mask the base rectangle with the custom path (there are multiple custom paths that can be chosen) but it's very rigid in that I have to try and set the viewBox to dimensions similar to size of the tile I'm testing on at that time, but then it doesn't fit the smaller one that might have a 16/9 aspect-ratio instead of a portrait one. I've also struggled to centre the inner SVG responsively, any CSS I seem to try to apply to it has no effect.
For instance I tried setting the x and y values of the custom path to 50% then add a transform: translate(-50%, -50%);
but it only took the x and y inline values into consideration.
The Code
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1200 1600">
<defs>
<mask id="organic_1_mask" x="0" y="0" width="100%" height="100%" >
<rect width="100%" height="100%" x="0" y="0" fill="white"/>
<svg x="15%" y="25%" overflow="visible">
<path d="m-.56,898.39c0,165.39,134.08,299.46,299.47,299.46s299.46-134.07,299.46-299.46c0,165.39,134.07,299.46,299.46,299.46s299.47-134.07,299.47-299.46-134.07-299.46-299.47-299.46c165.39,0,299.47-134.07,299.47-299.46S1063.22,0,897.83,0s-299.46,134.07-299.46,299.46C598.37,134.07,464.3,0,298.91,0S-.56,134.07-.56,299.46s134.08,299.46,299.47,299.46C133.52,598.93-.56,733-.56,898.39Z"/>
</svg>
</mask>
</defs>
<rect width="100%" height="100%" x="0" y="0" fill="' . $overlay_colour . '" mask="url(#organic_1_mask)"></rect>
</svg>
The above code is one of a few different SVG paths I have that can be chosen to created the 'cut-out' effect, it uses a base <rect>
to create the colour background and then the custom SVG path to mask through it. I end up with the SVG mostly not sizing up correctly to the parent container then once it is, it's a nightmare to responsively centre the inner SVG. I've added an image below so you can see how it currently displays on an example tile.
I've thought about maybe trying to generate the viewBox
dimensions via JS but it's more of a last resort to save on load times, open to any ideas that might achieve the same effect where a custom SVG shape can be picked and 'cut through' a background colour.
Broken Inline Code
<div class="cut-out-shape" style="background: url(<?= the_post_thumbnail_url(); ?>);-webkit-mask-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 1200 1200"%3E%3Cpath d="m-.56,898.39c0,165.39,134.08,299.46,299.47,299.46s299.46-134.07,299.46-299.46c0,165.39,134.07,299.46,299.46,299.46s299.47-134.07,299.47-299.46-134.07-299.46-299.47-299.46c165.39,0,299.47-134.07,299.47-299.46S1063.22,0,897.83,0s-299.46,134.07-299.46,299.46C598.37,134.07,464.3,0,298.91,0S-.56,134.07-.56,299.46s134.08,299.46,299.47,299.46C133.52,598.93-.56,733-.56,898.39Z" fill="black"/%3E%3C/svg%3E');
mask-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" width="200" height="200" viewBox="0 0 1200 1200"%3E%3Cpath d="m-.56,898.39c0,165.39,134.08,299.46,299.47,299.46s299.46-134.07,299.46-299.46c0,165.39,134.07,299.46,299.46,299.46s299.47-134.07,299.47-299.46-134.07-299.46-299.47-299.46c165.39,0,299.47-134.07,299.47-299.46S1063.22,0,897.83,0s-299.46,134.07-299.46,299.46C598.37,134.07,464.3,0,298.91,0S-.56,134.07-.56,299.46s134.08,299.46,299.47,299.46C133.52,598.93-.56,733-.56,898.39Z" fill="black"/%3E%3C/svg%3E');">