summaryrefslogtreecommitdiffstats
path: root/packaging/macos/src/svg2icns.sh
blob: c072646fe2f846df71eaa919ba81368bd0a43c3c (plain)
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
# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
#
# SPDX-License-Identifier: GPL-2.0-or-later

### description ################################################################

# Convert svg to icns. This is the "wrapper" that utilizes/requires caivrosvg
# and png2icns packages.

### shellcheck #################################################################

# shellcheck shell=bash # no shebang as this file is intended to be sourced

### dependencies ###############################################################

source "$(dirname "${BASH_SOURCE[0]}")"/cairosvg.sh
source "$(dirname "${BASH_SOURCE[0]}")"/png2icns.sh

### variables ##################################################################

# Nothing here.

### functions ##################################################################

function svg2icns_install
{
  cairosvg_install
  png2icns_install
}

function svg2icns
{
  local svg_file=$1
  local icns_file=$2
  local scale=$3   # optional

  if [ -z "$scale" ]; then
    scale=1
  fi

  local png_file
  png_file=$TMP_DIR/$(basename -s .svg "$svg_file").png

  # svg to png
  jhb run cairosvg -f png -s $scale -o "$png_file" "$svg_file"

  # png to icns
  cd "$TMP_DIR" || exit 1   # png2icns.sh outputs to current directory
  png2icns.sh "$png_file"

  mv "$(basename -s .png "$png_file")".icns "$icns_file"
}

### main #######################################################################

# Nothing here.