optimize detecting avatar image logilogic

cc @eviltrout @coding-horror