git: 7a62e423dcb8 - main - misc/flag-icons: supply three flag decoration flavors

From: Alexey Dokuchaev <danfe_at_FreeBSD.org>
Date: Thu, 08 May 2025 01:54:43 UTC
The branch main has been updated by danfe:

URL: https://cgit.FreeBSD.org/ports/commit/?id=7a62e423dcb89a620d07cdca43c01f06c110c33c

commit 7a62e423dcb89a620d07cdca43c01f06c110c33c
Author:     Alexey Dokuchaev <danfe@FreeBSD.org>
AuthorDate: 2025-05-08 01:52:50 +0000
Commit:     Alexey Dokuchaev <danfe@FreeBSD.org>
CommitDate: 2025-05-08 01:52:50 +0000

    misc/flag-icons: supply three flag decoration flavors
    
    - Add 16px height missing from the initial check-in
    - Factor out common shell code into simple() function
      and feed it with specifics; rounded() is special as
      it does more complicated image transformations
---
 misc/flag-icons/Makefile           | 11 ++++++++---
 misc/flag-icons/files/makeflags.sh | 36 ++++++++++++++++++++++++++++++++++--
 misc/flag-icons/pkg-descr          |  2 +-
 3 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/misc/flag-icons/Makefile b/misc/flag-icons/Makefile
index 39b9a896c51f..21cf09b196fc 100644
--- a/misc/flag-icons/Makefile
+++ b/misc/flag-icons/Makefile
@@ -19,12 +19,17 @@ NO_ARCH=	yes
 NO_INSTALL=	yes
 
 FLAGS_TOPDIR=	${PREFIX}/share/icons/${PORTNAME}
-FLAG_SIZES=	24 32 48 64 96 128 192 256 # 512 adds 27MB for .tbz package
+FLAG_SIZES=	16 24 32 48 64 96 128 192 256 # 512 adds 25+ MB for .tbz package
+
+FLAVORS=	plain bordered rounded
+
+.if ${FLAVOR:U:Nplain}
+PKGNAMESUFFIX=	-${FLAVOR}
+.endif
 
-# TODO: add bordered and plain versions maybe?
 do-build:
 	cd ${BUILD_WRKSRC}/flags && ${SH} ${FILESDIR}/makeflags.sh \
-	rounded_corners ${STAGEDIR}${FLAGS_TOPDIR}/rounded ${FLAG_SIZES}
+	${FLAVOR} ${STAGEDIR}${FLAGS_TOPDIR}/${FLAVOR} ${FLAG_SIZES}
 
 post-stage:
 	cd ${STAGEDIR}${PREFIX} && ${FIND} share -type f >> ${TMPPLIST}
diff --git a/misc/flag-icons/files/makeflags.sh b/misc/flag-icons/files/makeflags.sh
index ea16f8edd252..160212b7c673 100644
--- a/misc/flag-icons/files/makeflags.sh
+++ b/misc/flag-icons/files/makeflags.sh
@@ -1,5 +1,37 @@
+simple()
+{
+	local comment convert_extra_args destdir height ratio subdir t0 width
+
+	comment=$1; convert_extra_args=$2; destdir=$3; shift 3
+
+	for subdir in ?x?; do
+		ratio=${subdir%x*}/${subdir#*x}
+		for height; do
+			width=$((height * $ratio))
+			mkdir -p "$destdir/${width}x${height}"
+			echo -n "Generating $comment flags ${width}x${height}... "
+			t0=$(date +%s)
+			for flag in $subdir/*.svg; do
+				convert -resize ${width}x${height} $convert_extra_args \
+				"$flag" "$destdir/${width}x${height}/$(basename "$flag" svg)png"
+			done
+			echo "finished in $(date -ur $((`date +%s`-t0)) +%M:%S)"
+		done
+	done
+}
+
+plain()
+{
+	simple undecorated -strip "$@"
+}
+
+bordered()
+{
+	simple black-bordered '-shave 1x1 -bordercolor black -border 1 -strip' "$@"
+}
+
 # https://joeldare.com/rounding-image-corners-with-imagemagick
-rounded_corners()
+rounded()
 {
 	local destdir height mask radius ratio subdir t0 width
 
@@ -18,7 +50,7 @@ rounded_corners()
 
 			mkdir -p "$destdir/${width}x${height}"
 
-			echo -n "Generating flags ${width}x${height}... "
+			echo -n "Generating rounded corner flags ${width}x${height}... "
 			t0=$(date +%s)
 			for flag in $subdir/*.svg; do
 				convert -resize ${width}x${height} \
diff --git a/misc/flag-icons/pkg-descr b/misc/flag-icons/pkg-descr
index 7b0c5c3dd950..c1cedd032cda 100644
--- a/misc/flag-icons/pkg-descr
+++ b/misc/flag-icons/pkg-descr
@@ -1,2 +1,2 @@
 A curated collection of all country flags in 4x3 and 1x1 formats
-converted from SVG to PNG for various sizes, from 24px to 256px.
+converted from SVG to PNG for various sizes, from 16px to 256px.