fixing TypeError, ticket #12285 (rebased onto dev_5_0)



This is the same as gh-2518 but rebased onto dev_5_0.

----

this should fix error when opening image viewer from Image link.

To test it open image viewer, go to Image Link  and open given link in separate window.

TypeError issue was only noticed with big images.