Skip to content

Commit bda7a8f

Browse files
committed
Improve the codes so that it can be extened to support upper-case extensions in the future
1 parent 8f1d1e3 commit bda7a8f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

pygmt/figure.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,19 @@ def savefig(
298298
"png": "g",
299299
"pdf": "f",
300300
"jpg": "j",
301-
"jpeg": "j",
302301
"bmp": "b",
303302
"eps": "e",
304303
"tif": "t",
305304
"kml": "g",
306305
}
307306

308-
prefix = Path(fname).with_suffix("").as_posix()
309-
ext = Path(fname).suffix[1:] # suffix without .
307+
fname = Path(fname)
308+
prefix, suffix = fname.with_suffix("").as_posix(), fname.suffix
309+
ext = suffix[1:]
310+
# alias jpeg to jpg
311+
if ext == "jpeg":
312+
ext = "jpg"
313+
310314
if ext not in fmts:
311315
if ext == "ps":
312316
raise GMTInvalidInput(
@@ -329,9 +333,9 @@ def savefig(
329333

330334
self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
331335

332-
# rename .jpg to .jpeg
333-
if ext == "jpeg":
334-
Path(fname).with_suffix(".jpg").rename(fname)
336+
# Rename if file extension doesn't match the input file suffix
337+
if ext != suffix[1:]:
338+
fname.with_suffix("." + ext).rename(fname)
335339

336340
if show:
337341
launch_external_viewer(fname)

0 commit comments

Comments
 (0)