What about

```coffeescript
ensureImageExtension = (url) ->
  ext = url.split(".").pop()
  if /(png|jpe?g|gif)/.test(ext)
    url
  else
    "#{url}#.png"
```