gen-flags-go
This utility scrapes countryflags.com for the flag images it uses
This utility will download country flags in one or many different shapes. The output can either be in plain PNG files or in Base-64 encoding. You can also generate JSON lists of Base-64 encoded country flag images fairly easily with this utility.
Building
You must have Go installed in order to build this utility.
Run the following command to build the binary.
$ go get -u "github.com/nfnt/resize"
$ go build gen-flags.go
Basic Execution
The following command will download all images for all countries of all shapes and place them in the flags
directory. The directory will be automatically created if it does not exist.
./gen-flags -download -output-dir=./flags/
Filters
You can filter which countries and shapes are downloaded using the following command line parameters
-filter-countries=united-states-of-america,finland
-filter-shapes=rectangle,circle
To get a list of valid shapes and countries run the following
./gen-flags -list-shapes # for list of valid shapes
./gen-flags -list-countries # for list of valid countries
Changing Image Scale
You can change the scale of each shape you download by formatting the shape name as shape[scale%]
-filter-shapes=circle[150%],square[50%]
Note: When scaling higher than 100 images may start to become blurry
Output Location
You can specify an ouput directory using the -output-dir
command line agrument.
-output-dir=./flags/
Output Types
There are several output types you can select. Decide which one you want using the -output-type
command line argument.
-output-type=png
-output-type=b64
-output-type=b64-iso3166-numeric-json-file
-output-type=b64-iso3166-alpha2-json-file
-output-type=b64-iso3166-alpha3-json-file
When using the iso3166
output types, the result will be a json file storing the selected flags and countries defined in the following format
{
"ISO_CODE": {
"shape1": "...base64string...",
"shape2": "...base64string..."
}
}
Output File Name Format
You can change the file name format when using the png
and b64
output types using the -file-name-format
command line argument.
-file-name-format="{iso-alpha3}-{shape}"
The available file name format specifiers are:
{iso-alpha2}
{iso-alpha3}
{iso-numeric}
{country}
{shape}
{scale}
Note: Do not add a file extension to the file-name-format. This will be done automatically.
Shape Previews
These previews are each at 100% scale, hopefully this helps you when choosing a scale while downloading.