Skip to content
A utility for generating country flag images in both base64 and png formats using GoLang
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.


This utility scrapes 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.


You must have Go installed in order to build this utility.

Run the following command to build the binary.

$ go get -u ""
$ 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/


You can filter which countries and shapes are downloaded using the following command line parameters


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%]


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 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.


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.

Shape 100% Scale Dimensions Preview
Rectangle 800w x 421h rectangle
Square 250w x 250h square
Circle 250w x 250h circle
Wave 250w x 132h wave
Waving 250w x 167h waving
Button Square 250w x 250h button-square
Button Round 250w x 250h button-round
3D 250w x 167h 3d
3D Round 250w x 250h 3d-round
Heart 3D 250w x 227h heart-3d
You can’t perform that action at this time.