0

I want to create a bash script that can be executed from everywhere, that does this following:

  1. It creates images from a pdf file using pdftoppm:

    pdftoppm fileinput.pdf -png img -r 305.3

After all of the png images are there.

  1. It crops the all of png images 10 1920x1080 using mogrify:

    mogrify -crop 1920x1080+2+2 *.png


In short, I want to create a bash script that execute:

pdftoppm inputfile.pdf -png img -r 305.3 && mogrify -crop 1920x1080+2+2 *.png 

It will be like:

  ./mybashscript inputfile.pdf

And after I run the script, the output png images will be already cropped to 1920x1080.


Note: I know I can set the dimension of the output images by changing the -r value in pdftoppm. But I do not want to change that due to a reason.

1 Answers1

0

You may want to separate these tasks and do all of task 1 first (create image files from pdf), then all of task 2 (resize images). For an example of how to loop through and resize images, see https://stackoverflow.com/questions/14304480/batch-resize-images-and-output-images-to-new-folder-with-imagemagick

Update: So I haven't used pdftoppm so you'll have to refine that part of your script yourself but it looks like you may have that part down. Here's some starter code:

pdftoppm $1 -png img -r 305.3
magick mogrify -resize 1920x1080 *.png

More info on passing arguments to a script. Then make sure you save and put this script in your PATH so you can execute it from anywhere. Note that a more robust script would have error checking (making sure you passed in input files for example).