%% in output filename does not work properly
Posted: 2011-01-10T05:42:17-07:00
ImageMagick has a bug which prevents the use of arbitrary strings involving percent signs in output filenames. For example, say if I wanted to use "%d.jpg" as an output filename. The code implies that
convert source.jpg %%d.jpg
would be the way to go, however, this produces an output file called "%%d.jpg", not "%d.jpg" as expected. This is because InterpretImageFilename() does not set canonical=MagickTrue in either of the places where double-percent handling is done. So the output filename is fixed and then reverted.
If canonical is true for some other reason, it works, for example:
convert source.jpg %d-%%d.jpg
This produces a file called "0-%d.jpg". The fix is simple enough:
I've tested it.
Downstream bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=26233
convert source.jpg %%d.jpg
would be the way to go, however, this produces an output file called "%%d.jpg", not "%d.jpg" as expected. This is because InterpretImageFilename() does not set canonical=MagickTrue in either of the places where double-percent handling is done. So the output filename is fixed and then reverted.
If canonical is true for some other reason, it works, for example:
convert source.jpg %d-%%d.jpg
This produces a file called "0-%d.jpg". The fix is simple enough:
Code: Select all
Index: magick/image.c
===================================================================
--- magick/image.c (revision 3430)
+++ magick/image.c (working copy)
@@ -1797,8 +1797,10 @@
}
}
for (q=filename; *q != '\0'; q++)
- if ((*q == '%') && (*(q+1) == '%'))
+ if ((*q == '%') && (*(q+1) == '%')) {
(void) CopyMagickString(q,q+1,(size_t) (MaxTextExtent-(q-filename)));
+ canonical = MagickTrue;
+ }
if (canonical == MagickFalse)
(void) CopyMagickString(filename,format,MaxTextExtent);
return(strlen(filename));
Downstream bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=26233