开发者

Create ImageMagick Linux script

开发者 https://www.devze.com 2023-03-16 19:53 出处:网络
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 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
0

精彩评论

暂无评论...
验证码 换一张
取 消