Escape special characters in image link

Because based on your description, I am not sure what is your purpose doing the escape.

If you want to escape the URL, you might consider using WordPress internal esc_url() function

If you want to do some more low level control with PHP native function, you may consider urlencode() and you might have to manually urldecode() it in some cases depending on your purpose