Check for parse_url errors before checking getting pathinfo and doing in_array check. Also pass image types through a filter.