%% in output filename does not work properly

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
tstarling
Posts: 3
Joined: 2010-04-22T05:03:56-07:00
Authentication code: 8675308

%% in output filename does not work properly

Post by tstarling »

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:

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));
I've tested it.

Downstream bug: https://bugzilla.wikimedia.org/show_bug.cgi?id=26233
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: %% in output filename does not work properly

Post by magick »

Thanks for the bug report and patch. We'll get it into the next point release of ImageMagick, 6.6.7-1.
Post Reply