diff --git a/.github/workflows/optimize-and-deploy.yml b/.github/workflows/optimize-and-deploy.yml new file mode 100644 index 0000000..8914f8a --- /dev/null +++ b/.github/workflows/optimize-and-deploy.yml @@ -0,0 +1,37 @@ +name: Optimize and Deploy + +on: + push: + branches: + - main + +jobs: + optimize: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y webp librsvg2-bin + + - name: Optimization + run: | + ./optimize.sh -h 300 -q 100 -o out + + - name: Deploy + run: | + sudo chown -R $(whoami):$(whoami) . + git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" + git config --global user.name "$GITHUB_ACTOR" + cp -r out/* /tmp + cd /tmp + git init + git branch -M gh-pages + git add . + git commit -m "Optimize images" + git remote add origin "https://$GITHUB_ACTOR:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" + git push -f origin gh-pages diff --git a/optimize.sh b/optimize.sh new file mode 100755 index 0000000..ddbf9df --- /dev/null +++ b/optimize.sh @@ -0,0 +1,132 @@ +#!/bin/bash + +TEMP_DIR=temp +INPUT_DIR=src +OUTPUT_DIR=out + +WIDTH=0 +HEIGHT=300 +IMAGE_QUALITY=100 + +while getopts ":o:w:h:q:" opt; do + case ${opt} in + o ) + OUTPUT_DIR=$OPTARG + ;; + w ) + WIDTH=$OPTARG + ;; + h ) + HEIGHT=$OPTARG + ;; + q ) + IMAGE_QUALITY=$OPTARG + ;; + \? ) + echo "Usage: ./optimize.sh [-o output_dir] [-w width] [-h height] [-q image_quality]" + exit 1 + ;; + esac +done + +rm -rf "$TEMP_DIR" +mkdir -p "$OUTPUT_DIR" + +mkdir "$TEMP_DIR" +cp -r "$INPUT_DIR"/* "$TEMP_DIR" + +optimize_image() { + local input_file="$1" + local output_file="$2" + cwebp -q "$IMAGE_QUALITY" -m 6 -sharpness 0 -noalpha -resize "$WIDTH" "$HEIGHT" -quiet "$input_file" -o "$output_file" +} + +convert_svg_to_webp() { + local input_file="$1" + local output_file="$2" + local temp_png="${output_file}.png" + rsvg-convert -o "$temp_png" "$input_file" + optimize_image "$temp_png" "$output_file" + rm "$temp_png" +} + +optimize_webp() { + local input_file="$1" + local output_file="$2" + local temp_output="${output_file}.temp" + + if webpmux -info "$input_file" 2>&1 | grep -q "No. of frames: 1"; then + optimize_image "$input_file" "$temp_output" + else + gif2webp -q "$IMAGE_QUALITY" "$input_file" -o "$temp_output" + fi + + local original_size=$(stat -c %s "$input_file") + local new_size=$(stat -c %s "$temp_output") + + if (( new_size < original_size )); then + mv "$temp_output" "$output_file" + echo "Optimized: $input_file -> $output_file (reduced size from $original_size to $new_size)" + else + rm "$temp_output" + cp "$input_file" "$output_file" + echo "Copied without change: $input_file -> $output_file" + fi +} + +file_exists_in_output() { + local input_file="$1" + local filename=$(basename "$input_file") + [ -f "$OUTPUT_DIR/$filename" ] +} + +process_images() { + for img in "$TEMP_DIR"/*.{jpg,jpeg,png}; do + [ -f "$img" ] || continue + filename=$(basename "$img" .${img##*.}) + output_file="$OUTPUT_DIR/$filename.webp" + if ! file_exists_in_output "$output_file"; then + optimize_image "$img" "$output_file" + echo "Converted: $img -> $output_file" + fi + done +} + +process_svgs() { + for svg in "$TEMP_DIR"/*.svg; do + [ -f "$svg" ] || continue + filename=$(basename "$svg" .svg) + output_file="$OUTPUT_DIR/$filename.webp" + if ! file_exists_in_output "$output_file"; then + convert_svg_to_webp "$svg" "$output_file" + echo "Converted: $svg -> $output_file" + fi + done +} + +process_webps() { + for webp in "$TEMP_DIR"/*.webp; do + [ -f "$webp" ] || continue + filename=$(basename "$webp" .webp) + output_file="$OUTPUT_DIR/$filename.webp" + if ! file_exists_in_output "$output_file"; then + optimize_webp "$webp" "$output_file" + fi + done +} + +process_images +process_svgs +process_webps + +find "$TEMP_DIR" -type f ! -name '*.jpg' ! -name '*.jpeg' ! -name '*.png' ! -name '*.svg' -exec cp -v {} "$OUTPUT_DIR/" \; + +files_count=$(find "$INPUT_DIR" -type f | wc -l) +echo "$files_count files in $INPUT_DIR" + +total=$(find "$OUTPUT_DIR" -type f | wc -l) +echo "Total: $total files in $OUTPUT_DIR" + +rm -rf "$TEMP_DIR" + +echo "Optimization completed." diff --git a/src/21.jpeg b/src/21.jpeg new file mode 100644 index 0000000..59a3631 Binary files /dev/null and b/src/21.jpeg differ diff --git a/src/24k_magic.jpeg b/src/24k_magic.jpeg new file mode 100644 index 0000000..f963f5e Binary files /dev/null and b/src/24k_magic.jpeg differ diff --git a/src/after_hours.jpg b/src/after_hours.jpg new file mode 100644 index 0000000..c2b52af Binary files /dev/null and b/src/after_hours.jpg differ diff --git a/src/am.jpeg b/src/am.jpeg new file mode 100644 index 0000000..1ecd8f2 Binary files /dev/null and b/src/am.jpeg differ diff --git a/src/baby.jpeg b/src/baby.jpeg new file mode 100644 index 0000000..539987c Binary files /dev/null and b/src/baby.jpeg differ diff --git a/src/beauty_behind_the_madness.jpeg b/src/beauty_behind_the_madness.jpeg new file mode 100644 index 0000000..0a8ef5d Binary files /dev/null and b/src/beauty_behind_the_madness.jpeg differ diff --git a/src/before_you_go.jpeg b/src/before_you_go.jpeg new file mode 100644 index 0000000..c26393d Binary files /dev/null and b/src/before_you_go.jpeg differ diff --git a/src/billionaire.jpeg b/src/billionaire.jpeg new file mode 100644 index 0000000..e5fde90 Binary files /dev/null and b/src/billionaire.jpeg differ diff --git a/src/blinding_lights.jpeg b/src/blinding_lights.jpeg new file mode 100644 index 0000000..f9322a6 Binary files /dev/null and b/src/blinding_lights.jpeg differ diff --git a/src/cant_feel_my_face.jpeg b/src/cant_feel_my_face.jpeg new file mode 100644 index 0000000..6248453 Binary files /dev/null and b/src/cant_feel_my_face.jpeg differ diff --git a/src/careless_whisper.jpeg b/src/careless_whisper.jpeg new file mode 100644 index 0000000..6539e68 Binary files /dev/null and b/src/careless_whisper.jpeg differ diff --git a/src/creepin.jpeg b/src/creepin.jpeg new file mode 100644 index 0000000..9f20e7b Binary files /dev/null and b/src/creepin.jpeg differ diff --git a/src/divide.jpeg b/src/divide.jpeg new file mode 100644 index 0000000..86612d4 Binary files /dev/null and b/src/divide.jpeg differ diff --git a/src/dont_matter.jpeg b/src/dont_matter.jpeg new file mode 100644 index 0000000..c27875a Binary files /dev/null and b/src/dont_matter.jpeg differ diff --git a/src/doo_wops_hooligans.jpeg b/src/doo_wops_hooligans.jpeg new file mode 100644 index 0000000..b13720a Binary files /dev/null and b/src/doo_wops_hooligans.jpeg differ diff --git a/src/easy_on_me.jpeg b/src/easy_on_me.jpeg new file mode 100644 index 0000000..556ed95 Binary files /dev/null and b/src/easy_on_me.jpeg differ diff --git a/src/favourite_worst_nightmare.jpg b/src/favourite_worst_nightmare.jpg new file mode 100644 index 0000000..8396c2c Binary files /dev/null and b/src/favourite_worst_nightmare.jpg differ diff --git a/src/finesse.jpeg b/src/finesse.jpeg new file mode 100644 index 0000000..da4daa8 Binary files /dev/null and b/src/finesse.jpeg differ diff --git a/src/grenade.jpeg b/src/grenade.jpeg new file mode 100644 index 0000000..33cd2fd Binary files /dev/null and b/src/grenade.jpeg differ diff --git a/src/heartless.jpeg b/src/heartless.jpeg new file mode 100644 index 0000000..3924645 Binary files /dev/null and b/src/heartless.jpeg differ diff --git a/src/hello.jpeg b/src/hello.jpeg new file mode 100644 index 0000000..4128b1d Binary files /dev/null and b/src/hello.jpeg differ diff --git a/src/heroes_tonight.jpeg b/src/heroes_tonight.jpeg new file mode 100644 index 0000000..ec53c63 Binary files /dev/null and b/src/heroes_tonight.jpeg differ diff --git a/src/hopes_and_fears.jpeg b/src/hopes_and_fears.jpeg new file mode 100644 index 0000000..2e9ad0b Binary files /dev/null and b/src/hopes_and_fears.jpeg differ diff --git a/src/i_feel_it_coming.jpeg b/src/i_feel_it_coming.jpeg new file mode 100644 index 0000000..9d5511d Binary files /dev/null and b/src/i_feel_it_coming.jpeg differ diff --git a/src/in_your_eyes.jpeg b/src/in_your_eyes.jpeg new file mode 100644 index 0000000..f9e61f9 Binary files /dev/null and b/src/in_your_eyes.jpeg differ diff --git a/src/it_will_rain.jpeg b/src/it_will_rain.jpeg new file mode 100644 index 0000000..8016775 Binary files /dev/null and b/src/it_will_rain.jpeg differ diff --git a/src/locked_out_of_heaven.jpeg b/src/locked_out_of_heaven.jpeg new file mode 100644 index 0000000..f751cc0 Binary files /dev/null and b/src/locked_out_of_heaven.jpeg differ diff --git a/src/lonely.jpeg b/src/lonely.jpeg new file mode 100644 index 0000000..1c68847 Binary files /dev/null and b/src/lonely.jpeg differ diff --git a/src/marshmello.webp b/src/marshmello.webp new file mode 100644 index 0000000..a3f45b3 Binary files /dev/null and b/src/marshmello.webp differ diff --git a/src/my_dear_melancholy.jpeg b/src/my_dear_melancholy.jpeg new file mode 100644 index 0000000..f4220a7 Binary files /dev/null and b/src/my_dear_melancholy.jpeg differ diff --git a/src/never_gonna_give_you_up.jpg b/src/never_gonna_give_you_up.jpg new file mode 100644 index 0000000..46c432b Binary files /dev/null and b/src/never_gonna_give_you_up.jpg differ diff --git a/src/nothin_on_you.jpeg b/src/nothin_on_you.jpeg new file mode 100644 index 0000000..873544d Binary files /dev/null and b/src/nothin_on_you.jpeg differ diff --git a/src/on_&_on.jpeg b/src/on_&_on.jpeg new file mode 100644 index 0000000..9e4a1df Binary files /dev/null and b/src/on_&_on.jpeg differ diff --git a/src/out_of_time.jpeg b/src/out_of_time.jpeg new file mode 100644 index 0000000..6b5bbb9 Binary files /dev/null and b/src/out_of_time.jpeg differ diff --git a/src/peaches.jpeg b/src/peaches.jpeg new file mode 100644 index 0000000..28e263f Binary files /dev/null and b/src/peaches.jpeg differ diff --git a/src/rolling_in_the deep.jpeg b/src/rolling_in_the deep.jpeg new file mode 100644 index 0000000..61df30b Binary files /dev/null and b/src/rolling_in_the deep.jpeg differ diff --git a/src/rolling_in_the_deep.jpeg b/src/rolling_in_the_deep.jpeg new file mode 100644 index 0000000..9e6e2ac Binary files /dev/null and b/src/rolling_in_the_deep.jpeg differ diff --git a/src/save_your_tears.jpeg b/src/save_your_tears.jpeg new file mode 100644 index 0000000..593ec05 Binary files /dev/null and b/src/save_your_tears.jpeg differ diff --git a/src/shape_of_you.jpeg b/src/shape_of_you.jpeg new file mode 100644 index 0000000..670f0ca Binary files /dev/null and b/src/shape_of_you.jpeg differ diff --git a/src/shine.jpeg b/src/shine.jpeg new file mode 100644 index 0000000..7a84c26 Binary files /dev/null and b/src/shine.jpeg differ diff --git a/src/silk_sonic.jpeg b/src/silk_sonic.jpeg new file mode 100644 index 0000000..c563674 Binary files /dev/null and b/src/silk_sonic.jpeg differ diff --git a/src/skyfall.jpeg b/src/skyfall.jpeg new file mode 100644 index 0000000..ede42e6 Binary files /dev/null and b/src/skyfall.jpeg differ diff --git a/src/someone_like_you.jpeg b/src/someone_like_you.jpeg new file mode 100644 index 0000000..6c5e093 Binary files /dev/null and b/src/someone_like_you.jpeg differ diff --git a/src/someone_you_loved.jpeg b/src/someone_you_loved.jpeg new file mode 100644 index 0000000..e20e3b4 Binary files /dev/null and b/src/someone_you_loved.jpeg differ diff --git a/src/sorry.jpeg b/src/sorry.jpeg new file mode 100644 index 0000000..9e69409 Binary files /dev/null and b/src/sorry.jpeg differ diff --git a/src/starboy.jpeg b/src/starboy.jpeg new file mode 100644 index 0000000..9d5511d Binary files /dev/null and b/src/starboy.jpeg differ diff --git a/src/stay.jpeg b/src/stay.jpeg new file mode 100644 index 0000000..e1eef27 Binary files /dev/null and b/src/stay.jpeg differ diff --git a/src/sweater_weather.jpeg b/src/sweater_weather.jpeg new file mode 100644 index 0000000..e9508bc Binary files /dev/null and b/src/sweater_weather.jpeg differ diff --git a/src/symbolism.jpeg b/src/symbolism.jpeg new file mode 100644 index 0000000..825ff6b Binary files /dev/null and b/src/symbolism.jpeg differ diff --git a/src/thats_what_i_like.jpg b/src/thats_what_i_like.jpg new file mode 100644 index 0000000..1505e49 Binary files /dev/null and b/src/thats_what_i_like.jpg differ diff --git a/src/the_lazy_song.jpeg b/src/the_lazy_song.jpeg new file mode 100644 index 0000000..5a1aa08 Binary files /dev/null and b/src/the_lazy_song.jpeg differ diff --git a/src/treasure.jpeg b/src/treasure.jpeg new file mode 100644 index 0000000..a35b549 Binary files /dev/null and b/src/treasure.jpeg differ diff --git a/src/uptown_funk.jpeg b/src/uptown_funk.jpeg new file mode 100644 index 0000000..57644be Binary files /dev/null and b/src/uptown_funk.jpeg differ diff --git a/src/versace_on_the_floor.jpeg b/src/versace_on_the_floor.jpeg new file mode 100644 index 0000000..439be74 Binary files /dev/null and b/src/versace_on_the_floor.jpeg differ diff --git a/src/what_do_you_mean.jpeg b/src/what_do_you_mean.jpeg new file mode 100644 index 0000000..0ed9cdc Binary files /dev/null and b/src/what_do_you_mean.jpeg differ diff --git a/src/x.jpeg b/src/x.jpeg new file mode 100644 index 0000000..860fac9 Binary files /dev/null and b/src/x.jpeg differ diff --git a/src/yummy.jpeg b/src/yummy.jpeg new file mode 100644 index 0000000..05e1980 Binary files /dev/null and b/src/yummy.jpeg differ