static/images/generate-thumbs copy.sh
241 Zeilen · 6.5 KB · Shell
| 1 | |
| 2 | |
| 3 | # Option 1: PNG zu JPEG konvertieren (meist dramatische Größenreduktion) |
| 4 | for i in `find posts -type f ! -name "thumb-*.png" -name "*.png" | grep -v thumbs`; |
| 5 | do |
| 6 | filefull="${i##*/}" |
| 7 | file="${filefull%.[^.]*}" |
| 8 | ext="${filefull:${#file} + 1}" |
| 9 | dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 10 | source="${dir}${file}.${ext}" |
| 11 | |
| 12 | if [ ! -d ${dir}thumbs/ ]; |
| 13 | then |
| 14 | mkdir ${dir}thumbs/ |
| 15 | fi |
| 16 | |
| 17 | # Als JPEG speichern für dramatische Größenreduktion |
| 18 | dest="${dir}thumbs/${file}.jpg" |
| 19 | |
| 20 | if [ -f ${dest} ]; |
| 21 | then |
| 22 | continue; |
| 23 | fi; |
| 24 | |
| 25 | # PNG zu JPEG mit weißem Hintergrund (für Transparenz) |
| 26 | convert ${source} -background white -flatten -quality 85 -strip ${dest}; |
| 27 | echo "convert ${source} -background white -flatten -quality 85 -strip ${dest};" |
| 28 | done |
| 29 | |
| 30 | echo -e "\n=== webp Konvertierung ===" |
| 31 | # for i in posts/**/*.{jpg,jpeg,png,JPG,JPEG,PNG}; do |
| 32 | for i in `find posts -type f ! -name "*.svg" ! -name "*.webp" ! -name "*.gif" | grep -v thumbs`; do |
| 33 | # echo "i: $i" |
| 34 | [ ! -f "$i" ] && continue |
| 35 | |
| 36 | filename=$(basename "$i") |
| 37 | name="${filename%.*}" |
| 38 | dir=$(dirname "$i") |
| 39 | output="${dir}/${name}.webp" |
| 40 | |
| 41 | [ -f "$output" ] && continue |
| 42 | |
| 43 | # Dateigröße prüfen |
| 44 | size=$(stat -f%z "$i" 2>/dev/null || stat -c%s "$i" 2>/dev/null) |
| 45 | |
| 46 | # Qualität basierend auf Dateigröße anpassen |
| 47 | if [ "$size" -gt 1000000 ]; then # > 1MB |
| 48 | quality=75 |
| 49 | elif [ "$size" -gt 500000 ]; then # > 500KB |
| 50 | quality=80 |
| 51 | else |
| 52 | quality=85 |
| 53 | fi |
| 54 | |
| 55 | echo "Konvertiere: $i (${size} bytes) -> $output (quality: $quality)" |
| 56 | cwebp -q $quality "$i" -o "$output" |
| 57 | done |
| 58 | |
| 59 | # echo "Generate Thumbnails" |
| 60 | # for i in `find posts -type f ! -name "*.svg" ! -name "*.webp" | grep -v thumbs`; |
| 61 | # do |
| 62 | # # echo $i; |
| 63 | # filefull="${i##*/}" |
| 64 | # file="${filefull%.[^.]*}" |
| 65 | # ext="${filefull:${#file} + 1}" |
| 66 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 67 | # source="${dir}${file}.${ext}" |
| 68 | # if [ ! -d ${dir}thumbs/ ]; |
| 69 | # then |
| 70 | # mkdir ${dir}thumbs/ |
| 71 | # fi |
| 72 | # dest="${dir}thumbs/${file}-600x600.${ext}" |
| 73 | # if [ -f ${dest} ]; |
| 74 | # then |
| 75 | # continue; |
| 76 | # fi; |
| 77 | # convert ${source} -thumbnail 600x600 ${dest} |
| 78 | # echo "convert ${source} -thumbnail 600x600 ${dest}"; |
| 79 | # done |
| 80 | |
| 81 | |
| 82 | # Option 2: Wenn Sie PNG behalten möchten - mit pngquant (installieren mit: sudo apt install pngquant) |
| 83 | # for i in `find posts -type f ! -name "thumb-*.png" -name "*.png" | grep -v thumbs`; |
| 84 | # do |
| 85 | # filefull="${i##*/}" |
| 86 | # file="${filefull%.[^.]*}" |
| 87 | # ext="${filefull:${#file} + 1}" |
| 88 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 89 | # source="${dir}${file}.${ext}" |
| 90 | # |
| 91 | # if [ ! -d ${dir}thumbs/ ]; |
| 92 | # then |
| 93 | # mkdir ${dir}thumbs/ |
| 94 | # fi |
| 95 | # dest="${dir}thumbs/${file}.${ext}" |
| 96 | # |
| 97 | # if [ -f ${dest} ]; |
| 98 | # then |
| 99 | # continue; |
| 100 | # fi; |
| 101 | # |
| 102 | # # PNG verlustbehaftet komprimieren (kann 50-80% Größenreduktion bringen) |
| 103 | # pngquant --quality=65-80 --output ${dest} ${source}; |
| 104 | # done |
| 105 | |
| 106 | # Option 3: Moderne WebP Format (beste Komprimierung) |
| 107 | # for i in `find posts -type f ! -name "thumb-*.png" -name "*.png" | grep -v thumbs`; |
| 108 | # do |
| 109 | # filefull="${i##*/}" |
| 110 | # file="${filefull%.[^.]*}" |
| 111 | # ext="${filefull:${#file} + 1}" |
| 112 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 113 | # source="${dir}${file}.${ext}" |
| 114 | # |
| 115 | # if [ ! -d ${dir}thumbs/ ]; |
| 116 | # then |
| 117 | # mkdir ${dir}thumbs/ |
| 118 | # fi |
| 119 | # dest="${dir}thumbs/${file}.webp" |
| 120 | # |
| 121 | # if [ -f ${dest} ]; |
| 122 | # then |
| 123 | # continue; |
| 124 | # fi; |
| 125 | # |
| 126 | # # Als WebP mit hoher Komprimierung |
| 127 | # convert ${source} -quality 80 -define webp:lossless=false ${dest}; |
| 128 | # done |
| 129 | |
| 130 | # # Option 1: Einfache Qualitätsreduzierung (empfohlen für die meisten Fälle) |
| 131 | # for i in `find posts -type f ! -name "thumb-*.png" -name "*.png" | grep -v thumbs`; |
| 132 | # do |
| 133 | # filefull="${i##*/}" |
| 134 | # file="${filefull%.[^.]*}" |
| 135 | # ext="${filefull:${#file} + 1}" |
| 136 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 137 | # source="${dir}${file}.${ext}" |
| 138 | |
| 139 | # if [ ! -d ${dir}thumbs/ ]; |
| 140 | # then |
| 141 | # mkdir ${dir}thumbs/ |
| 142 | # fi |
| 143 | |
| 144 | # dest="${dir}thumbs/${file}.${ext}" |
| 145 | |
| 146 | # # if [ -f ${dest} ]; |
| 147 | # # then |
| 148 | # # continue; |
| 149 | # # fi; |
| 150 | |
| 151 | # # Komprimierung mit reduzierter Qualität (80% ist ein guter Startwert) |
| 152 | # echo "convert ${source} -quality 80 -strip ${dest};" |
| 153 | # # convert ${source} -quality 60 -strip ${dest}; |
| 154 | # convert ${source} -quality 30 -strip -interlace Plane -resize '1000x1000>' ${dest}; |
| 155 | # # convert ${source} -strip -define png:compression-level=9 ${dest}; |
| 156 | # done |
| 157 | |
| 158 | # Option 2: Aggressivere Komprimierung |
| 159 | # convert ${source} -quality 60 -strip -interlace Plane ${dest}; |
| 160 | |
| 161 | # Option 3: Für PNG spezifisch optimiert |
| 162 | # convert ${source} -strip -define png:compression-level=9 ${dest}; |
| 163 | |
| 164 | # Option 4: Automatische Optimierung basierend auf Dateigröße |
| 165 | # convert ${source} -quality 85 -strip -resize '2000x2000>' ${dest}; |
| 166 | |
| 167 | #################################################################################################### |
| 168 | |
| 169 | # for i in `find posts -type f ! -name "thumb-*.png" -name "*.png" | grep -v thumbs`; |
| 170 | # do |
| 171 | # filefull="${i##*/}" |
| 172 | # file="${filefull%.[^.]*}" |
| 173 | # ext="${filefull:${#file} + 1}" |
| 174 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 175 | # source="${dir}${file}.${ext}" |
| 176 | # if [ ! -d ${dir}thumbs/ ]; |
| 177 | # then |
| 178 | # mkdir ${dir}thumbs/ |
| 179 | # fi |
| 180 | # dest="${dir}thumbs/${file}.${ext}" |
| 181 | # if [ -f ${dest} ]; |
| 182 | # then |
| 183 | # continue; |
| 184 | # fi; |
| 185 | # convert ${source} -thumbnail 200x200 ${dest}; |
| 186 | # done |
| 187 | |
| 188 | |
| 189 | |
| 190 | ################# |
| 191 | |
| 192 | |
| 193 | #for i in `find static/images/galleries -type f ! -name "*-thumb.jpg" -name "*.jpg"`; |
| 194 | #do |
| 195 | # echo $i; |
| 196 | # if [ -f ${i%.*}-thumb.jpg ]; |
| 197 | # then |
| 198 | # continue; |
| 199 | # fi; |
| 200 | # convert $i -thumbnail 300x300 ${i%.*}-thumb.jpg; |
| 201 | #done |
| 202 | |
| 203 | # for i in `find static/images/galleries -type f ! -name "thumb-*.jpg" -name "*.jpg" | grep -v thumbs`; |
| 204 | # do |
| 205 | # filefull="${i##*/}" |
| 206 | # file="${filefull%.[^.]*}" |
| 207 | # ext="${filefull:${#file} + 1}" |
| 208 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 209 | # source="${dir}${file}.${ext}" |
| 210 | # if [ ! -d ${dir}thumbs/ ]; |
| 211 | # then |
| 212 | # mkdir ${dir}thumbs/ |
| 213 | # fi |
| 214 | # dest="${dir}thumbs/${file}.${ext}" |
| 215 | # if [ -f ${dest} ]; |
| 216 | # then |
| 217 | # continue; |
| 218 | # fi; |
| 219 | # convert ${source} -thumbnail 300x300 ${dest}; |
| 220 | # done |
| 221 | |
| 222 | # for i in `find static/img/posts -type f ! -name "*.svg" | grep -v thumbs`; |
| 223 | # do |
| 224 | # # echo $i; |
| 225 | # filefull="${i##*/}" |
| 226 | # file="${filefull%.[^.]*}" |
| 227 | # ext="${filefull:${#file} + 1}" |
| 228 | # dir=$(echo ${i} | sed -e "s/${file}\.${ext}//") |
| 229 | # source="${dir}${file}.${ext}" |
| 230 | # if [ ! -d ${dir}thumbs/ ]; |
| 231 | # then |
| 232 | # mkdir ${dir}thumbs/ |
| 233 | # fi |
| 234 | # dest="${dir}thumbs/${file}.${ext}" |
| 235 | # if [ -f ${dest} ]; |
| 236 | # then |
| 237 | # continue; |
| 238 | # fi; |
| 239 | # convert ${source} -thumbnail 600x600 ${dest} |
| 240 | # echo "convert ${source} -thumbnail 300x300 ${dest}"; |
| 241 | # done |