A common issue when building Content Management Systems for end-users using WYSIWYG Editors like CKEditor is that users can upload images within the editor, embed them, and then resize them.
After saving the content, the embedded (original) image URLs need to be replaced by their properly resized counterparts. Imagine a 3000 x 3000 photograph uploaded by a user, manually resized in the WYSIWYG editor to 300 x 300 Pixels - it needs to be resized automatically to prevent a huge source file from being loaded.
The task is pretty straightforward, and I've implemented it a number of times (albeit with regular expressions, which is why I'm looking for a replacement :) - walk through the DOM, search for images, see whether the size of the image source file differs from that specified in the img
tag and if it does, replace the original image by an automatically resized one.
There are a few small quirks along the way (some WYWSIYG editors prefer to use width="300"
, others the width: 300px
CSS version etc.).
My question is, is there a ready-made, high-quality PHP solution that does this well, and takes the quirks into account?