How to integrate an image haystack replacement technique
This generally isn't necessary in Craft. You can use a Matrix Field and combination of Matrix Blocks to build advanced content with flexible images. This is really the best way to go if it's an option.