Skip to content

Commit df7ab9a

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

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

pygmt/figure.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -298,15 +298,20 @@ 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+
309+
prefix, suffix = fname.with_suffix("").as_posix(), fname.suffix
310+
ext = suffix[1:]
311+
# alias jpeg to jpg
312+
if ext == "jpeg":
313+
ext = "jpg"
314+
310315
if ext not in fmts:
311316
if ext == "ps":
312317
raise GMTInvalidInput(
@@ -329,9 +334,9 @@ def savefig(
329334

330335
self.psconvert(prefix=prefix, fmt=fmt, crop=crop, **kwargs)
331336

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

336341
if show:
337342
launch_external_viewer(fname)

0 commit comments

Comments
 (0)