Skip to content

Commit

Permalink
#3147 icon: add script to generate image formats and sizes
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <[email protected]>
  • Loading branch information
pbek committed Nov 10, 2024
1 parent 88f60f6 commit f29e59e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
11 changes: 11 additions & 0 deletions icons/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Icons

To generate icons for the whole applications, run the following command:

```bash
# Generate all icons
./generate-icons.sh
```

It uses `icon.svg` and `icon-dark.svg` as the source files and generates the
icons in the `icons` folder, for `src/images` and the snaps.
61 changes: 61 additions & 0 deletions icons/generate-icons.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env bash

# Exit on any error
set -e

# Configuration
SRC_IMAGES_DIR="../src/images"
INPUT_SVG="icon.svg"
INPUT_DARK_SVG="icon-dark.svg"
SIZES_APP=(16 24 32 48 64 96 128 256 512)
APP_NAME="QOwnNotes"

# Check if input file exists
if [ ! -f "$INPUT_SVG" ]; then
echo "Error: Input file '$INPUT_SVG' not found!"
exit 1
fi

#Check if dark input file exists
if [ ! -f "$INPUT_DARK_SVG" ]; then
echo "Error: Input file '$INPUT_DARK_SVG' not found!"
exit 1
fi

# Function to convert images
convert_icon() {
local size=$1
local output_file=$2
local input_file=$3

# Use fallback to $INPUT_SVG if no local input file is provided
if [ -z "$input_file" ]; then
input_file=$INPUT_SVG
fi

echo "Converting to ${size}x${size} -> ${output_file}"
# magick "$input_file" -resize "${size}x${size}" "$output_file"
rsvg-convert -w "$size" -h "$size" "$input_file" -o "$output_file"
}

# Generate all sizes
convert_icon 128 "icon.png"
convert_icon 16 "icon.icns"
convert_icon 48 "icon.ico"
convert_icon 800 "icon-800.png"
convert_icon 512 "../snap/gui/QOwnNotes.png"
convert_icon 512 "../build-systems/github/snap.qt6/gui/QOwnNotes.png"
convert_icon 512 "../build-systems/snap/snapcraft/snap/gui/QOwnNotes.png"

# Generate app icons
for size in "${SIZES_APP[@]}"; do
convert_icon ${size} "${SRC_IMAGES_DIR}/icons/${size}x${size}/apps/${APP_NAME}.png"
done

# Copy to src/images
echo "Copying to src/images"
cp icon.png ${SRC_IMAGES_DIR}/icon.png
cp ${INPUT_DARK_SVG} ${SRC_IMAGES_DIR}/icon-dark.svg
convert_icon 128 ${SRC_IMAGES_DIR}/icon-dark.png ${INPUT_DARK_SVG}

echo "Icon conversion complete!"
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ fix-settings-ui-file:
process-trace:
sudo lurk --attach `procs QOwnNotes | fzf --height 40% --layout reverse | awk '{print $1}'`

# Generate the icons for the whole project based on icons/icon.svg and icons/icon-dark.svg
[group('icons')]
generate-icons:
cd icons &&./generate-icons.sh

# Format all justfiles
[group('linter')]
just-format:
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
findutils
gnused
ripgrep
librsvg
];

buildInputs = with pkgs; with qt6; [
Expand Down

0 comments on commit f29e59e

Please sign in to comment.