First: it is not clear where, in your opinion, there is any security problem at all. Second:
getimagesize () also makes no sense to trust, as the file can be in GIF, JPEG, JPG, PNG format
If the file is really in the format of GIF, JPEG, JPG, PNG, and getimagesize returns its proportions, then this means that it is a real file in the format of GIF, JPEG, JPG, PNG. Maybe, of course, this is a rargipeg, but you are not going to execute it as a PHP script?
The third and last. Well, you downloaded the script with the extension .gif . Where does security collapse in this case? Do you server feeds files with .gif extension to PHP interpreter? The only problem that can be here is the problem with cgi.fix_pathinfo in php-fpm , and while you live on the hosting, the hoster should deal with this (and this is a very old bug that, it seems, fixed).
While you are working with a file as with an image, and do not expose files that fall under the “feed to the interpreter” rule (i.e. files with the .php extension) to the public access, nothing will happen.