trim function doesn't do what you think it does, although it would be nice if it did.
There are other ways to accomplish the task. The URL Toolkit app will parse the URL for you and let you choose any part(s) you like.
rex command can do it, too.
... | rex field=url "(?<url>.*)\/"
Slightly simplified version:
| makeresults | eval url="fqdn/A/B/C/file.png" | rex field=url "^(?P<result>.*)/[^/]+$"