The resulting image has to be base64 encoded to be included like that.
So you need to do the following:
- Edit the image
- Get resulting image in data string.
- To get image string, you either store it to filesystem and read it through file_get_contents() (useful for cache) or use imagejpeg() without location, which places the image in output buffer. To get the value from output buffer use ob_start() and ob_get_contents().
- Convert data string of the image to base64 (using base64_encode())
- Return this string to browser
- Set image "src" field to "data:image/png;base64,[BASE64]" where [BASE64] is the string returned from PHP.