Good day to all!
A little bit of entry. I have long dreamed of writing this little program ... I didn’t take it for a long time, because I thought it was very difficult :) but in the end, everything turned out pretty simple and fast!
I sometimes update the site with a large number of images. When they bring me a bunch of photos of absolutely different resolutions, which need to be adjusted to one size - I am horrified ... but anyway - it is necessary to compress.
As a result, this script was born.
Also, if you have accumulated a lot of “professional” photos, in which only the main idea is important, not quality, then it will not prevent you from using it too!
Opportunities:1) Resizing a file or all images in a folder according to a given mask.
2) Image optimization
3) Conversion to available formats (jpg, gif, bmp, png ..., in general there are many formats)
script requires
imagemagick package
installedI had it (probably because I have LinuxMint). I hope on ubunt too.
It has several unpleasant properties:1) with files that have spaces in the names, misunderstandings will occur, so it’s better to rename them.
2) is very sensitive to registers (as in and everything in the world * nix), so remember that jpeg and JPEG are different things!
3) it may be neochen friendly for someone, but if you do everything as he asks, everything will be fine
')
well, here's the code itself:
#!/bin/bash
function Resize {
echo "Enter name of file (with directory) (Ex: /home/user/Desktop/picture.jpg)"
echo "or enter mask to resize all pictures in folder (Ex: /home/user/*.jpg)"
read nfile
echo "Enter size or percent (50% or 640x480 or only x-size)" # . , , " ":)
read size
mogrify -resize $size $nfile
echo "Done"
read Keypress
}
function Convert { # , ,
echo "Enter name of file (with directory) (Ex: /home/user/Desktop/picture.jpg)"
echo "or enter mask to convert all pictures in folder (Ex: /home/user/*.jpg)"
read nfile
echo "Enter type (just png or jpg without mask)"
read typep
mogrify -format $typep $nfile
echo "Done"
read Keypress
}
function Optim {
echo "Enter name of file (with directory) (Ex: /home/user/Desktop/picture.jpg)"
echo "or enter mask to optimize all pictures in folder (Ex: /home/user/*.jpg)"
read nfile
echo "Enter name of folder to save pictures " # , ( , , 2 ....)
read nfold
mkdir $nfold
convert $nfile -type optimize $nfold/pic.jpg # pic_0.jpg pic, img , _i
echo "Done!"
read Keypress
}
#
while [ $var=true ]; do
echo
echo "---------MENU---------"
select var in "Resize" "Optimize" "Convert" "Exit"; do
break
done
echo "$var"
case $var in
"Resize") Resize;;
"Optimize") Optim;;
"Convert") Convert;;
"Exit") exit ;;
esac
done
The script was written for the first time, so do not swear hard!)