Photo import code breaks channel import
Created by: anaqreon
Mike Macgirvin:
see anything wrong?
'no decode delegate for this image format `'
Imagick->readimageblob('...')
This is happening in the photo_factory class constructor on line 600 of include/photo/photo_driver.php; so before we pass an image string to the photo driver we need to check that it is actually an image string. Since we just fetched the image from the network, we've got the HTML headers. They should provide a Content-Type of 'image/jpeg','image/gif','image/png', etc. Should probably parse this down completely and individually check each of these possibilities, but I'm going to cheat and just check for 'image/'. You are welcome to improve on this as it will save somebody a whitescreen some day when they come across a profile photo that's image/tiff or image/x-sun-raster or something.
The original photo import code was done before imagemagick was integrated, and the gd library just returns a null image - which we do check for. Another possible solution is to put this into a try/catch block and catch the exception that imagemagick is throwing and save a lot of extra header parsing. I suspect that imagemagick has thousands of potential exceptions though, so it isn't obvious which ones we should catch besides just the 'no decode delegate' exception. I don't have imagemagick source handy and we'd need that to find out the symbolic error name, unless you were to just throw some random noise or html at it and print out the exception to discover the actual name. ... [or you could just try/catch any exception at all and set "is_valid" to false.] This probably isn't a perfect solution either (seems nothing is) because I suspect that imagemagick will throw errors on stuff like proprietary EXIF headers they don't support when in fact it can still parse the photo. ...
It was #fixed an hour or two ago, but as described in my post it was a quick fix and a compromise and will return to haunt us at some later date unless fixed correctly.
https://github.com/redmatrix/hubzilla/commit/9ab335626cdaad433c8f5b6d7fd4d980c1b37742