Simple function for parsing base64-encoded inline jpg images from html code and converting them to resized image files
string htmlImagesToFilesAndResize ( string $html, number $max_width, number $max_height )
Returns parsed HTML string with all inline base64 jpg images converted to image files with tags replaced by the ones that links to files. For example:
<img src="data:image/jpg;base64, [base64 string.....]" width="x" height="y">
<img src="data:image/jpg;base64, [base64 string.....]" width="xx" height="yy">
<img src="data:image/jpg;base64, [base64 string.....]" width="xxx" height="yyy">
[etc]
will be converted to
<img src="dl/1.jpg" width="x" height="y">
<img src="dl/2.jpg" width="xx" height="yy">
<img src="dl/3.jpg" width="xxx" height="yyy">
[etc]
It also generates 100px x 100px thumbnail images to dl/thumbnails/[imgname]. This is very handy if you need to build a simple HTML editor with php and you don't want to mess with inline jpg images. See and run the example to test its power!
HTML string as is when handling data generated by browser in contenteditable element
Max image width; Image scales down to this point with the correct ratio
Max image height; if, after scaled down by max_width, height is still greater than max_height, the image will be scaled down more so that its height is equal to max_height