Create PDF Thumbnail - shell (bash) script
Zkonvertuje libovolnou stránku z PDF souboru na obrázek PNG
# set functions
CONVERT()
{
num=0
name=$(basename "$file" .pdf | cut -d- -f1 | sed 's/.$//' | tr ' ' '-')
ext="png"
mark='/Users/danielpitra/Documents/--- Wordpress ---/- DanielPitra.cz -/--- img ---/watermark2.png'
for page in ${pages[*]}
do
if [[ ! -e "$path"/"$name"_$num.$ext ]]; then
echo "Creating thumbnail ..."
convert -quiet -density 300 -quality 100 -thumbnail x1815 -background white -alpha remove "$file"[$page] "$path"/"$name"_$num.$ext
while :
do
read -n 1 -s -p "Add watermark? [Y/n]" watermark
case $watermark in
""|[yY] )
echo ""
echo "Adding watermark to thumbnail ..."
convert -quiet "$path"/"$name"_$num.$ext "$mark" -gravity center -composite "$path"/"$name"_$num.$ext
echo "DONE!"
break
;;
[nN] )
echo ""
echo "DONE!"
break
;;
* )
echo ""
echo "Use only 'y' or 'n' !"
esac
done
else
while [[ -e "$path"/"$name"_$num.$ext ]]; do
(( num++ ))
done
echo "Creating thumbnail ..."
convert -quiet -density 300 -quality 100 -thumbnail x1815 -background white -alpha remove "$file"[$page] "$path"/"$name"_$num.$ext
while :
do
read -n 1 -s -p "Add watermark? [Y/n]" watermark
case $watermark in
""|[yY] )
echo ""
echo "Adding watermark to thumbnail ..."
convert -quiet "$path"/"$name"_$num.$ext "$mark" -gravity center -composite "$path"/"$name"_$num.$ext
echo "DONE!"
break
;;
[nN] )
echo ""
echo "DONE!"
break
;;
* )
echo ""
echo "Use only 'y' or 'n' !"
esac
done
fi
done
}
# start
echo ""
while :
do
read -e -p "Path to PDF: " file
if [[ -d "$file" ]]; then
echo "'$file' is a directory"
echo "Enter path to PDF File!"
elif [[ -z "$file" ]]; then
echo "Enter path to file!"
elif [[ "$file" = /* ]]; then
file=$(echo "$file" | tr -d "\\")
break
else
echo "Enter FULL path!"
fi
done
while :
do
read -e -p "Page to be converted (leave blank for first): " -a pages
if [[ -z "$pages" ]]; then
pages="0"
break
else
break
fi
done
while :
do
read -e -p "Path to save: " path
if [[ -f "$path" ]]; then
echo "'$path' is file"
echo "Enter path to save thumbnail into!"
elif [[ -z "$path" ]]; then
path='/Users/danielpitra/Documents/--- Wordpress ---/- DanielPitra.cz -/--- img ---/pdf thumbs'
break
else
break
fi
done
CONVERT
Neformátovaný
Přidáno: 9.2.2020
Expirace: Neuvedeno