Not displaying .gif images in HTML + PHP

     

I am having an issue displaying .gif files.


In short I want to create a sort of banner rotator where you display a different .gif everytime you refresh the page.


The code was 100% working with .jpg but with .gif I get just an empty page (not the icon with the broken image when the loading fails).


I've found this page where it says to check the GD library which in my case is v2.2.3 (everything is enabled). This is getting a bit frustrating...


May be some noob question for which I apologize... Can anybody help?


Here is the part of the script that is not working: