Fix duplicate file name extension

If a filename extension and a format are specified with the same string,
we create a file with a double file extension. Ie:

```javascript
py.image.save_as(figure, 'filename2.png', 'png')
```
This will produce a file named filename2.png.png. When ext and format
are both present, the fix will only append format to the filename if the
format is different from ext. Ie:
```javascript
py.image.save_as(figure, 'filename2.png', 'pdf')
```
This will create filename2.png.pdf.