From a4ecb29d50b6be1dbdafdef177e66d23bf1132ee Mon Sep 17 00:00:00 2001 From: matthias wandel Date: Fri, 18 Jun 2021 13:18:49 -0300 Subject: [PATCH] Cut off old extension if copypgcmd specifies a new extension --- src/util.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/util.c b/src/util.c index 32062d0..e31035d 100755 --- a/src/util.c +++ b/src/util.c @@ -354,7 +354,23 @@ static void CopyJpgFileCmd(char * src, char * dest) } if (CopyJpgCmd[a] == '&' && (CopyJpgCmd[a+1] == 'i' || CopyJpgCmd[a+1] == 'o')){ - strncpy(ExecString+e, CopyJpgCmd[a+1] == 'i' ? src : dest, sizeof(ExecString)-e-1); + if (CopyJpgCmd[a+1] == 'o'){ + if (CopyJpgCmd[a+2] == '.'){ + // If it's specified "&o.", that means cut off the old extension. + // That way, we can specify a copyjpgcmd in imgcomp.conf to convert + // to a different image format. Example using imagemagick convert: + // copyjpgcmd = convert -quality 60 "&i" "&o.webp" + int extension = 0; + for (int b=0;dest[b];b++){ + if (dest[b] == '.') extension = b; + } + if (extension) dest[extension] = '\0'; + } + strncpy(ExecString+e, dest, sizeof(ExecString)-e-1); + }else{ + strncpy(ExecString+e, src, sizeof(ExecString)-e-1); + } + a += 1; e = strlen(ExecString); continue;