27

I convert a pdf file to jpg images by using ImageMagick like this:

convert -density 600 foo.pdf foo.jpg

The created jpg images are named foo-1.jpg, foo-10.jpg and so on.

Is there way to 0-pad the output file names to foo-01.jpg etc.?

Jan Doggen
  • 4,108
  • 10
  • 36
  • 51
ironsand
  • 2,179
  • 7
  • 30
  • 48

1 Answers1

40

ImageMagick accepts format specifiers in its command line:

convert -density 600 foo.pdf foo-%02d.jpg

Quote from the doc:

Filename References

Optionally, use an embedded formatting character to write a sequential image list. Suppose our output filename is image-%d.jpg and our image list includes 3 images. You can expect these images files to be written:

image-0.jpg
image-1.jpg
image-2.jpg
mpy
  • 27,002
  • 7
  • 85
  • 97
  • I tried this and get `convert-im6.q16: attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408.` – lacostenycoder Jan 26 '22 at 21:16
  • 1
    It works after the fix I needed which I [found here](https://stackoverflow.com/questions/52998331/imagemagick-security-policy-pdf-blocking-conversion) – lacostenycoder Jan 26 '22 at 21:29