diff --git a/deploy-this/compres-with-structure.sh b/deploy-this/compres-with-structure.sh new file mode 100755 index 0000000..9c64655 --- /dev/null +++ b/deploy-this/compres-with-structure.sh @@ -0,0 +1 @@ +python3 compress-with-structure.py \ No newline at end of file diff --git a/deploy-this/compress-with-structure.py b/deploy-this/compress-with-structure.py new file mode 100644 index 0000000..8dc7521 --- /dev/null +++ b/deploy-this/compress-with-structure.py @@ -0,0 +1,51 @@ +import os +from PIL import Image, UnidentifiedImageError +from shutil import copy2 + +# Ścieżki katalogów +input_folder = "src/main/resources/static/zaklik-public-images" # Folder źródłowy +output_folder = "src/main/resources/static/zaklik-public-images" # Folder docelowy + +# Funkcja kompresująca obrazy +def compress_image(input_path, output_path): + try: + with Image.open(input_path) as img: + img_format = img.format # Zachowaj format pliku + if img_format in ["JPEG", "PNG"]: + img.save(output_path, optimize=True, quality=15) + else: + copy2(input_path, output_path) # Kopiuj bez zmian, jeśli format nie jest obsługiwany + except UnidentifiedImageError: + print(f"Nie rozpoznano formatu obrazu: {input_path}") + +# Funkcja do przetwarzania plików w folderze +def process_folder(input_folder, output_folder): + for root, _, files in os.walk(input_folder): + for file in files: + # Ścieżka do pliku wejściowego + input_path = os.path.join(root, file) + + # Tworzenie ścieżki docelowej z odpowiednią strukturą katalogów + relative_path = os.path.relpath(root, input_folder) + target_dir = os.path.join(output_folder, relative_path) + os.makedirs(target_dir, exist_ok=True) + + # Obsługa plików już skompresowanych + if "(compressed)" in file: + continue + if "properties" in file: + continue + # Generowanie nazwy pliku wyjściowego + name, ext = os.path.splitext(file) + output_file = f"{name}(compressed){ext}" + output_path = os.path.join(target_dir, output_file) + # Sprawdzenie, czy skompresowany plik już istnieje + if os.path.exists(output_path): + print(f"Pominięto, plik już istnieje: {output_path}") + continue + # Kompresja pliku + print(f"Kompresowanie: {input_path} -> {output_path}") + compress_image(input_path, output_path) + +# Wykonanie skryptu +process_folder(input_folder, output_folder) diff --git a/deploy-this/convert-img-by-image-magic.sh b/deploy-this/convert-img-by-image-magic.sh new file mode 100755 index 0000000..4a19dda --- /dev/null +++ b/deploy-this/convert-img-by-image-magic.sh @@ -0,0 +1,42 @@ +INPUT_DIR="./src/main/resources/static/zaklik-public-images" # Folder z oryginalnymi obrazami +OUTPUT_DIR="./src/main/resources/static/zaklik-public-images-generated" # Główny folder do zapisu obrazów w nowych formatach + +# Iteracja po wszystkich plikach w katalogu wejściowym i jego podkatalogach +find "$INPUT_DIR" -type f | while read -r file; do + # Relatywna ścieżka pliku w katalogu wejściowym + relative_path="${file#$INPUT_DIR/}" + + # Ścieżka do katalogu docelowego + target_dir="$OUTPUT_DIR/$(dirname "$relative_path")" + + # Nazwa pliku bez rozszerzenia + filename=$(basename "$file" | cut -f 1 -d '.') + + # Ścieżki docelowych plików w formatach WebP i AVIF + webp_file="$target_dir/$filename.webp" + avif_file="$target_dir/$filename.avif" + + # Sprawdzenie, czy oba pliki już istnieją + if [ -f "$webp_file" ] && [ -f "$avif_file" ]; then + echo "Pomijam plik: $file (już skompresowany)" + continue + fi + + # Tworzenie podkatalogu w katalogu docelowym + mkdir -p "$target_dir" + + # Konwersja do WebP (jeśli plik nie istnieje) + if [ ! -f "$webp_file" ]; then + convert "$file" -quality 80 "$webp_file" + echo "Skompresowano do WebP: $webp_file" + fi + + # Konwersja do AVIF (jeśli plik nie istnieje) + if [ ! -f "$avif_file" ]; then + convert "$file" -quality 80 "$avif_file" + echo "Skompresowano do AVIF: $avif_file" + fi +done + +echo "Konwersja zakończona." + diff --git a/deploy-this/convert-img.js b/deploy-this/convert-img.js new file mode 100644 index 0000000..efd124f --- /dev/null +++ b/deploy-this/convert-img.js @@ -0,0 +1,33 @@ +const sharp = require('sharp'); +const fs = require('fs'); +const path = require('path'); + +const inputDir = './src/main/resources/static/zaklik-public-images'; // Folder z oryginalnymi obrazami +const outputDir = './src/main/resources/static/main-images/optimized-by-sharp'; // Folder do zapisu obrazów w nowych formatach + +const formats = ['webp', 'avif']; + +fs.readdir(inputDir, (err, files) => { + if (err) { + console.error('Error reading input directory:', err); + return; + } + + files.forEach(file => { + const inputFile = path.join(inputDir, file); + const fileName = path.parse(file).name; + + formats.forEach(format => { + const outputFile = path.join(outputDir, `${fileName}.${format}`); + sharp(inputFile) + .toFormat(format, { quality: 80 }) + .toFile(outputFile, (err, info) => { + if (err) { + console.error(`Error converting ${file} to ${format}:`, err); + } else { + console.log(`Converted ${file} to ${format} format.`); + } + }); + }); + }); +}); diff --git a/package-lock.json b/package-lock.json index 31cf58d..93434a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@ngx-translate/core": "^16.0.3", "@ngx-translate/http-loader": "^16.0.0", "bootstrap": "^5.3.3", + "date-fns": "^4.1.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -9423,6 +9424,15 @@ "integrity": "sha512-GAj5FOq0Hd+RsCGVJxZuKaIDXDf3h6GQoNEjFgbLLI/trgtavwUbSnZ5pVfg27DVCaWjIohryS0JFwIJyT2cMg==", "dev": true }, + "node_modules/date-fns": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/date-fns/-/date-fns-4.1.0.tgz", + "integrity": "sha512-Ukq0owbQXxa/U3EGtsdVBkR1w7KOQ5gIBqdH2hkvknzZPYvBxb/aa6E8L7tmjFtkwZBu3UXBbjIgPo/Ez4xaNg==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/kossnocorp" + } + }, "node_modules/date-format": { "version": "4.0.14", "resolved": "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz", diff --git a/package.json b/package.json index cd44407..c799b01 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ "@ngx-translate/core": "^16.0.3", "@ngx-translate/http-loader": "^16.0.0", "bootstrap": "^5.3.3", + "date-fns": "^4.1.0", "rxjs": "~7.8.0", "tslib": "^2.3.0", "zone.js": "~0.14.10" @@ -47,4 +48,4 @@ "typescript-eslint": "8.10.0", "vite": "^5.4.10" } -} \ No newline at end of file +} diff --git a/src/app/about-me/about-me.component.html b/src/app/about-me/about-me.component.html index 55a5d9f..7c8f103 100644 --- a/src/app/about-me/about-me.component.html +++ b/src/app/about-me/about-me.component.html @@ -8,19 +8,19 @@