fix : only open connection for images if not in local 

+ better handling of errors
Merge pull request #353 from tyrcho/fixes

urgent fix : only open connection for images if not in local