Prior to answering your question, I think you should step back and consider other options, here are some options:
1. Start using the image core component (although most likely the hardest one due to business people I guess?)
2. Update your image component to inherit (proxy) from the image core component (may be a sensitive change but you may want to pursue this or option #1 for the long term)
3. Update the component the way you are trying to do it and to answer your question: the only thing you need to know is which format the "src" will need to be built to be leveraged by the frontEnd, which seems you already know:
src={baseresourcepath}.{img}.{extension}That being said, due to your method is returning a String, you can manually check when a GIF(another format) image is used and manually return the expected format in the getter.
4. Return directly the GIF's file source without any transformation format, due GIF and WEBP are formats already optimized for web it won't necessarily take advantage of the transformations process, so I think you will be safe as well. In other words, return simply "/content/dam/mygif.gif". (Please double check this is ok with your performance 🙂 )