diff --git a/.gitignore b/.gitignore index 0cc06aa..6dc3764 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ public !.gitkeep -cwebp +magick diff --git a/install.sh b/install.sh index 6d589f7..dd0a170 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,2 @@ -wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.2.2-rc1-linux-x86-64.tar.gz -tar -xf *.tar.gz -mv libwebp-*/bin/cwebp . -rm -r libwebp-* +wget https://download.imagemagick.org/ImageMagick/download/binaries/magick +chmod +x magick \ No newline at end of file diff --git a/run_prepare_img.py b/run_prepare_img.py new file mode 100644 index 0000000..9bafa42 --- /dev/null +++ b/run_prepare_img.py @@ -0,0 +1,58 @@ +import os +import subprocess + +exportFolder = "public" +sourceFolder = "../strapi.accords-library.com/public/uploads/" +method = "6" + +presets = { + "small": { + "maxSize": "512", + "quality": "60", + "format": "webp" + }, + "medium": { + "maxSize": "1024", + "quality": "75", + "format": "webp" + }, + "large": { + "maxSize": "2048", + "quality": "80", + "format": "webp" + }, + "og": { + "maxSize": "512", + "quality": "60", + "format": "jpg" + } +} + +print("Try create main folder:", exportFolder) +if not os.path.isdir(exportFolder): os.mkdir(exportFolder) + +for preset in presets: + tmpFolder = exportFolder + "/" + preset + print("Try create preset folder:", tmpFolder) + if not os.path.isdir(tmpFolder): os.mkdir(tmpFolder) + +files = os.listdir(sourceFolder) +files = [file for file in files if not file.startswith("thumbnail_") and not file == ".gitkeep"] +for index, file in enumerate(files): + fName, _ = os.path.splitext(file) + for presetName in presets: + preset = presets[presetName] + exportFile = exportFolder + "/" + presetName + "/" + fName + "." + preset["format"] + if not os.path.isfile(exportFile): + command = [] + command += ["./magick"] + command += [sourceFolder + file] + command += ["-thumbnail " + preset["maxSize"] + "x" + preset["maxSize"] + "\>"] + command += ["-quality " + preset["quality"]] + if preset["format"] == "webp": command += ["-define webp:alpha-quality=" + preset["quality"]] + if preset["format"] == "webp": command += ["-define webp:method=" + method] + command += [exportFile] + + command = " ".join(command) + subprocess.call(command, shell=True) + print("DONE (" + str(index) + "/" + str(len(files)) + ") -", presetName, "-", fName) \ No newline at end of file diff --git a/run_prepareimg.sh b/run_prepareimg.sh deleted file mode 100755 index 48df6de..0000000 --- a/run_prepareimg.sh +++ /dev/null @@ -1,25 +0,0 @@ -mkdir public -mkdir public/small -mkdir public/medium -mkdir public/large - -echo "Working on small images" - -for f in ../strapi.accords-library.com/public/uploads/*; do - filename=$(basename "$f") - ./cwebp -short -m 6 -q 60 -alpha_q 60 -mt -resize 0 512 $f -o public/small/${filename%.*}.webp -done - -echo "Working on medium images" - -for f in ../strapi.accords-library.com/public/uploads/*; do - filename=$(basename "$f") - ./cwebp -short -m 6 -q 75 -alpha_q 75 -mt -resize 0 1024 $f -o public/medium/${filename%.*}.webp -done - -echo "Working on large images" - -for f in ../strapi.accords-library.com/public/uploads/*; do - filename=$(basename "$f") - ./cwebp -short -m 6 -q 80 -alpha_q 80 -mt -resize 0 2048 $f -o public/large/${filename%.*}.webp -done \ No newline at end of file