File: render-graphics.sh

package info (click to toggle)
kaidan 0.15.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 9,376 kB
  • sloc: cpp: 30,143; xml: 1,623; sh: 522; python: 34; makefile: 5
file content (59 lines) | stat: -rwxr-xr-x 1,874 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/bash -e

# SPDX-FileCopyrightText: 2023 Melvin Keskin <melvo@olomono.de>
#
# SPDX-License-Identifier: GPL-3.0-or-later

KAIDAN_DIRECTORY=$(dirname "$(readlink -f "${0}")")/..
OUTPUT_DIRECTORY="${KAIDAN_DIRECTORY}/misc/rendered-graphics"
OPTIMIZE_PNG_SCRIPT="${KAIDAN_DIRECTORY}/utils/optimize-png.sh"

echo "*****************************************"
echo "Rendering graphics"
echo "*****************************************"

render_group_chat_avatar() {
    render_svg_with_margin data/images/kaidan.svg group-chat-avatar.png 300 300 18
}

render_mastodon_avatar() {
    render_svg_with_margin data/images/kaidan.svg mastodon-avatar.png 400 400 18
}

render_mastodon_header() {
    render_svg data/images/chat-page-background.svg mastodon-header.png 824 824
}

# $1: relative input file path
# $2: output filename
# $3: width
# $4: height
# $5: margin
render_svg_with_margin() {
    input_file_path="${KAIDAN_DIRECTORY}/${1}"
    temporary_file_name=$(basename "${1}")
    temporary_file_path="${OUTPUT_DIRECTORY}/tmp-${temporary_file_name}"
    output_file_path="${OUTPUT_DIRECTORY}/${2}"
    inkscape -o "${temporary_file_path}" -w "${3}" -h "${4}" --export-margin="${5}" "${input_file_path}"
    inkscape -o "${output_file_path}" -w "${3}" -h "${4}" "${temporary_file_path}"
    rm "${temporary_file_path}"
    "${OPTIMIZE_PNG_SCRIPT}" "${output_file_path}"
    echo "Created ${output_file_path}"
}

# $1: relative input file path
# $2: output filename
# $3: width
# $4: height
render_svg() {
    input_file_path="${KAIDAN_DIRECTORY}/${1}"
    output_file_path="${OUTPUT_DIRECTORY}/${2}"
    inkscape -o "${output_file_path}" -w "${3}" -h "${4}" "${input_file_path}"
    "${OPTIMIZE_PNG_SCRIPT}" "${output_file_path}"
    echo "Created ${output_file_path}"
}

mkdir -p "${OUTPUT_DIRECTORY}"
render_group_chat_avatar
render_mastodon_avatar
render_mastodon_header