AdSense Mobile Ad

Tuesday, August 19, 2014

Public Domain Flags Archive (in Vector Image Format)

Some time ago, when I was implementing the EMCCountryPickerController component I described in some earlier posts (such as this one), I soon realised I needed high quality images of the flags of all the countries listed in the ISO 3166-1 standard. And since the EMCCountryPickerController library is GPL-licensed, I needed images whose license was compatible with it in order to distribute them together with the component.

I found decent collections of flags in the internet but at the end I decided to build my own, especially in order to overcome problems that arose from the limited resolution of many image collections.

I picked the flags from Wikimedia Commons since they're available in SVG format (a widely used vector image format). This way, if I need to, I can render a flag at any resolution.

I then assembled a GitHub repository where you can find:
  • All the flags in SVG format.
  • All the flags in PNG format scaled to a width of 256 pixels.
  • All the flags in PNG format, scaled to a width of 512 pixels.

The following is a shell script that can be used to render the flags archive at the desired widths.

#!/bin/sh
# This script resizes all SVG files svg/*.svg to PNG files with the desired
# width. This script assumes that the following source and output directories
# already exist:
# * svg/
# * png/w
# for each target width w.
# Loop on the list of desired widths.
for res in 256 512
do
for i in svg/*.svg
do
IMAGE_NAME=$(basename $i .svg)
rsvg-convert -w ${res} $i -o png/${res}/${IMAGE_NAME}.png
done
done
view raw render-flags.sh hosted with ❤ by GitHub
The script requires librsvg to be installed.

2 comments:

Anonymous said...

Many, many, and many thanks to you!!!!

Enrico M. Crisostomo said...

You're welcome, I'm glad it helped!