Skip to content

Commit

Permalink
Cut off old extension if copypgcmd specifies a new extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthias-Wandel committed Jun 18, 2021
1 parent 380d781 commit a4ecb29
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a4ecb29

Please sign in to comment.