I have an imagemagick convert command that I use from the shell and I would like to create a linux exec to run it, so I don't have to always run this.
I am converting a PDF file to JPEG files, and this is what I use: convert -density 300 *.pdf -alpha off -scale 1500x2000 -quality 70 jpegFiles.jpg
What I would like the linux exec file to do is run the above convert and instead of jpegFiles, to have the actual PDF filename. Of course, f开发者_开发问答or every page jpeg file it would have filename-0.jpg, filename-1.jpg, filename-2.jpg, etc.
I am using Ubuntu. Thank you.
save this in a file and place it in a dir like $HOME/.bin
eg. $HOME/.bin/pdf2jpg
for file in "$@"; do
convert -density 300 "$file" -alpha off -scale 1500x2000 -quality 70 "${file%.*}-%d.jpg"
done
make it executable
chmod +x $HOME/.bin/pdf2jpg
and add that dir to the PATH variable
echo "PATH=$PATH:$HOME/.bin" >> $HOME/.bash_profile # assuming you use bash
create a dir named as your pdf along with -images suffix and place the files in there
for file in "$@"; do
dir="${file%.*}-images"
mkdir -p "$dir"
convert -density 300 "$file" -alpha off -scale 1500x2000 -quality 70 "$dir/${file%.*}-%d.jpg"
done
精彩评论