I know this code looks redundant, but IIRC it's there to prevent a very specific security bug.  From my internal notes:

The issue as reported by Mateusz Goik:
```
ISSUE #9: Watermark code accepts arbitrarily named files
Reported by Mateusz Goik
Affects 3.0+
Introduced in 4b4e9e8e45465012805854dd322431f87f2b09c7 (pre 3.0)
Admin users can upload an arbitrarily named file as long as it begins with a valid GIF, JPEG or PNG then access that file directly
Ticket #1855
Fixed in fd4296c70ffe9c274a1e4215191955a41c4e98e2
```

From his security report:
```
1. Run the watermark module
2. Paste code into the image -> echo "<?php phpinfo();?>" >> a.jpg
3. Change name "a.jpg" to "a.php"
4. Upload -> http://localhost/gallery3/index.php/admin/watermarks
5. http://localhost/gallery3/var/modules/watermark/a.php = image + php
code :)
```

So we want to make absolutely sure that if we identify the watermark as a gif, it's got a ".gif" extension.  I'm a little low on time to do the analysis here - are we still safe if we remove this check?