Shell – Sort jpg according to creation date and convert to single pdf

jpegosxpdfshellsort

On a Mac, how can I sort about 2400 jpg according to their creation date (i. e. stat -f %SB) via terminal and convert them in that order into one pdf?

What if one jpg has been created today at 11:10 pm and a second one shortly after within the same minute at 11:10 pm? Are there seconds in the creation date, which can be taken into account?

Best Answer

A simple command line with ImageMagick convert works for me.

I tested with the following command line (in a directory with 14 png files), and there will be one picture per page in the pdf file.

convert  *.png out-parrot.pdf

But there can be problems with some versions of convert

It works as intended with the version of convert in Parrot 4.4

$convert --version
Version: ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org

but it does not work with the version of convert in Ubuntu 18.04.1 LTS (up to date in February 2019)

$ convert --version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org

This version is 'not authorized' to write pdf files

$ convert  *.png out-ubuntu.pdf
convert-im6.q16: not authorized `out-ubuntu.pdf' @ error/constitute.c/WriteImage/1037.

$ apt-cache policy imagemagick
imagemagick:
  Installed: 8:6.9.7.4+dfsg-16ubuntu6.4
  Candidate: 8:6.9.7.4+dfsg-16ubuntu6.4
  Version table:
 *** 8:6.9.7.4+dfsg-16ubuntu6.4 500
        500 http://se.archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages
        500 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages
        100 /var/lib/dpkg/status
     8:6.9.7.4+dfsg-16ubuntu6 500
        500 http://se.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

Via an Ubuntu mailing list I had the following answer (that converting to pdf was turned off because of problems with ImageMagick vulnerabilities)

Is this a bug in ImageMagick convert, specifically for Ubuntu 18.04 LTS, or is converting to pdf turned off by intention?

The change was intentional. See https://usn.ubuntu.com/3785-1/

Thanks, Jeremy Bicha

Related Question