Create ImageMagick Linux script

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, for every page jpeg file it would have filename-0.jpg, filename-1.jpg, filename-2.jpg, etc.

I am using Ubuntu. Thank you.

-------------Problems Reply------------

save this in a file and place it in a dir like $HOME/.bin
eg. $HOME/.bin/pdf2jpg

for file in "[email protected]"; do
convert -density 300 "$file" -alpha off -scale 1500x2000 -quality 70 "${file%.*}-%d.jpg"

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 "[email protected]"; do
mkdir -p "$dir"
convert -density 300 "$file" -alpha off -scale 1500x2000 -quality 70 "$dir/${file%.*}-%d.jpg"

Category:linux Views:0 Time:2011-07-03

Related post

Copyright (C), All Rights Reserved.

processed in 0.078 (s). 11 q(s)