Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

please add the Anarchy flag #62

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
@@ -0,0 +1,4 @@

.venv venv:
virtualenv -ppython2 .venv
.venv/bin/pip install imread numpy==1.16
21 changes: 21 additions & 0 deletions README.md
Expand Up @@ -31,3 +31,24 @@ If a previously visited site uses this same code, the file is already in the cac
NB: It won't work in https environments. You can download the css files and include them locally instead.

See *the cheese wiki*: http://www.cheesewiki.com/ for an example

## Adding a new flag

These scripts require an old version of numpy and are python2 based, so it's probably best to setup a virtual environment. Run or see `make venv`

Once you're in your virtual environment, or otherwise have old versions of python stuff installed, run

```
./add_gloss.py <filename.png>
```

to add the gloss layer on the top of the flag for a unified look, and then


```
./add_flag <name> <countrycode> <filename.png>
```

If countrycode is not going to be a 2 letter code, prefix it with `_`

to add the file to the appropriate stylesheets and image
79 changes: 79 additions & 0 deletions add_flag.py
@@ -0,0 +1,79 @@
#!/usr/bin/env python2

import sys
import imread
import tempfile
import subprocess
import os

def append_images(orig):
def scale(out, sz):
subprocess.check_call(["convert", orig,
"-scale", sz,
out])
subprocess.check_call(["convert", out,
"-background", "none",
"-gravity", "center",
"-extent", sz,
out])
def append(f1, f2):
subprocess.check_call(["convert",
f1, f2,
"-append", f1])

tmpdir = tempfile.mkdtemp()
out_16 = os.path.join(tmpdir, "16.png")
out_32 = os.path.join(tmpdir, "32.png")
scale(out_16, "16x16")
scale(out_32, "32x32")
append("images/flags16.png", out_16)
append("images/flags32.png", out_32)

# sanity checks
sh16 = imread.imread("images/flags16.png").shape
assert sh16[0] % 16 == 0
assert sh16[1] == 16
sh32 = imread.imread("images/flags32.png").shape
assert sh32[0] % 32 == 0
assert sh32[1] == 32
return sh16[0] - 16, sh32[0] - 32

if __name__ == '__main__':
try:
name, code, image = sys.argv[1:]
except ValueError:
print "usage: {} name code image".format(sys.argv[0])
sys.exit(1)

# validate the code - 2 lower case letters or starts with _
is_2_letter = (len(code) == 2 and code == code.lower() and code.isalpha())
assert is_2_letter or (code[0] == '_')

# append the new images
offset_16, offset_32 = append_images(image)

# add to the CSS
open("stylesheets/flags16.css", "a").write(".f16 .{}{{background-position:0 -{}px;}}\n".format(code, offset_16))
open("stylesheets/flags32.css", "a").write(".f32 .{}{{background-position:0 -{}px;}}\n".format(code, offset_32))

# and the SCSS
lines16 = open("stylesheets/flags16.scss").readlines()
idx = [l.strip() for l in lines16].index('} // .f16 - DO NOT REMOVE THIS LINE')
lines16.insert(idx, " .{}{{background-position:0 -{}px;}}\n".format(code, offset_16))
open("stylesheets/flags16.scss", "w").writelines(lines16)

lines32 = open("stylesheets/flags32.scss").readlines()
idx = [l.strip() for l in lines32].index('} // .f32 - DO NOT REMOVE THIS LINE')
lines32.insert(idx, " .{}{{background-position:0 -{}px;}}\n".format(code, offset_32))
open("stylesheets/flags32.scss", "w").writelines(lines32)

# and the index.html
html_lines = open("index.html").readlines()
indices = [i for i, l in enumerate(html_lines)
if l.strip() == '<!-- DO NOT REMOVE THIS LINE - AUTOMATIC INSERTION MARK -->']
assert len(indices) == 2
# insert last entry first
ABBR = code.upper() if is_2_letter else " "
html_lines.insert(indices[1], '<abbr>{}</abbr><li class="flag {}">{}</li><br/>\n'.format(ABBR, code, name))
html_lines.insert(indices[0], '<abbr>{}</abbr><li class="flag {}">{}</li><br/>\n'.format(ABBR, code, name))
open("index.html", "w").writelines(html_lines)
17 changes: 17 additions & 0 deletions add_gloss.py
@@ -0,0 +1,17 @@
#!/usr/bin/env python

import sys
import imread
import numpy as np

for f in sys.argv[1:]:
print(f)
im = imread.imread(f)[:, :, :3]
ramp = np.zeros(im.shape)
ramp[...] = 0.5
half = ramp.shape[0] / 2
ramp[:half, :, :] = np.linspace(0.7, 0.5, half).reshape((half, 1, 1))
new = 1.0 - 2 * (1 - ramp) * (1 - im.astype(float) / 255.0)
new = new * 255
new = new.astype(np.uint8)
imread.imsave("bumped_" + f, new)
Binary file modified images/flags16.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified images/flags32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 47 additions & 4 deletions index.html
Expand Up @@ -91,7 +91,6 @@
<abbr>DM</abbr><li class="flag dm">Dominica</li><br/>
<abbr>DO</abbr><li class="flag do">Dominican Republic</li><br/>
<abbr>DZ</abbr><li class="flag dz">Algeria</li><br/>
<abbr> </abbr><li class="flag ea island"><i>EA</i>Ceuta and Melilla (ES)</li><br/>
<abbr>EC</abbr><li class="flag ec">Ecuador</li><br/>
<abbr>EE</abbr><li class="flag ee">Estonia</li><br/>
<abbr>EG</abbr><li class="flag eg">Egypt</li><br/>
Expand All @@ -105,7 +104,6 @@
<abbr>FK</abbr><li class="flag fk island">Falkland Islands</li><br/>
<abbr>FM</abbr><li class="flag fm">Micronesia</li><br/>
<abbr>FO</abbr><li class="flag fo island">Faroe Islands</li><br/>
<abbr> </abbr><li class="flag fq deprecated"><i>FQ</i>(now TF)</li><br/>
<abbr>FR</abbr><li class="flag fr">France</li><br/>
<abbr>GA</abbr><li class="flag ga">Gabon</li><br/>
<abbr>GB</abbr><li class="flag gb">United Kingdom</li><br/>
Expand Down Expand Up @@ -320,6 +318,29 @@
<abbr> </abbr><li class="flag _Tibet">Tibet</li><br/>
<abbr> </abbr><li class="flag _United_Nations">United Nations</li><br/>
<abbr> </abbr><li class="flag _Wales">Wales</li><br/>
<abbr> </abbr><li class="flag _Klingon">Klingon</li><br/>
<abbr> </abbr><li class="flag _United_Federation_of_Planets">United Federation of Planets</li><br/>
<abbr> </abbr><li class="flag _Pirate">Pirate</li><br/>
<abbr> </abbr><li class="flag _Starfleet">Starfleet</li><br/>
<abbr> </abbr><li class="flag _DOOP">D.O.O.P.</li><br/>

<abbr> </abbr><li class="flag _GoT_Arryn">Arryn</li><br/>
<abbr> </abbr><li class="flag _GoT_Baratheon">Baratheon</li><br/>
<abbr> </abbr><li class="flag _GoT_Greyjoy">Greyjoy</li><br/>
<abbr> </abbr><li class="flag _GoT_Lannister">Lannister</li><br/>
<abbr> </abbr><li class="flag _GoT_Martell">Martell</li><br/>
<abbr> </abbr><li class="flag _GoT_Stark">Stark</li><br/>
<abbr> </abbr><li class="flag _GoT_Targaryen">Targaryen</li><br/>
<abbr> </abbr><li class="flag _GoT_Tully">Tully</li><br/>
<abbr> </abbr><li class="flag _GoT_Tyrell">Tyrell</li><br/>

<abbr> </abbr><li class="flag _Esperanto">Esperanto</li><br/>
<abbr> </abbr><li class="flag _OGS">Online Go Server</li><br/>
<abbr>LH</abbr><li class="flag lh">Lord Howe Island</li><br/>
<abbr> </abbr><li class="flag _cat">Catalonia</li><br/>
<abbr> </abbr><li class="flag _LGBT">LGBT+ Pride</li><br/>
<!-- DO NOT REMOVE THIS LINE - AUTOMATIC INSERTION MARK -->

</ul>

<ul class="f32">
Expand Down Expand Up @@ -391,7 +412,6 @@
<abbr>DM</abbr><li class="flag dm">Dominica</li><br/>
<abbr>DO</abbr><li class="flag do">Dominican Republic</li><br/>
<abbr>DZ</abbr><li class="flag dz">Algeria</li><br/>
<abbr> </abbr><li class="flag ea island"><i>EA</i>Ceuta and Melilla (ES)</li><br/>
<abbr>EC</abbr><li class="flag ec">Ecuador</li><br/>
<abbr>EE</abbr><li class="flag ee">Estonia</li><br/>
<abbr>EG</abbr><li class="flag eg">Egypt</li><br/>
Expand All @@ -405,7 +425,6 @@
<abbr>FK</abbr><li class="flag fk island">Falkland Islands</li><br/>
<abbr>FM</abbr><li class="flag fm">Micronesia</li><br/>
<abbr>FO</abbr><li class="flag fo island">Faroe Islands</li><br/>
<abbr> </abbr><li class="flag fq deprecated"><i>FQ</i>(now TF)</li><br/>
<abbr>FR</abbr><li class="flag fr">France</li><br/>
<abbr>GA</abbr><li class="flag ga">Gabon</li><br/>
<abbr>GB</abbr><li class="flag gb">United Kingdom</li><br/>
Expand Down Expand Up @@ -620,6 +639,30 @@
<abbr> </abbr><li class="flag _Tibet">Tibet</li><br/>
<abbr> </abbr><li class="flag _United_Nations">United Nations</li><br/>
<abbr> </abbr><li class="flag _Wales">Wales</li><br/>
<abbr> </abbr><li class="flag _Klingon">Klingon</li><br/>
<abbr> </abbr><li class="flag _United_Federation_of_Planets">United
Federation of Planets</li><br/>
<abbr> </abbr><li class="flag _Starfleet">Starfleet</li><br/>
<abbr> </abbr><li class="flag _Pirate">Pirate</li><br/>
<abbr> </abbr><li class="flag _DOOP">D.O.O.P.</li><br/>

<abbr> </abbr><li class="flag _GoT_Arryn">Arryn</li><br/>
<abbr> </abbr><li class="flag _GoT_Baratheon">Baratheon</li><br/>
<abbr> </abbr><li class="flag _GoT_Greyjoy">Greyjoy</li><br/>
<abbr> </abbr><li class="flag _GoT_Lannister">Lannister</li><br/>
<abbr> </abbr><li class="flag _GoT_Martell">Martell</li><br/>
<abbr> </abbr><li class="flag _GoT_Stark">Stark</li><br/>
<abbr> </abbr><li class="flag _GoT_Targaryen">Targaryen</li><br/>
<abbr> </abbr><li class="flag _GoT_Tully">Tully</li><br/>
<abbr> </abbr><li class="flag _GoT_Tyrell">Tyrell</li><br/>

<abbr> </abbr><li class="flag _Esperanto">Esperanto</li><br/>
<abbr> </abbr><li class="flag _OGS">Online Go Server</li><br/>
<abbr>LH</abbr><li class="flag lh">Lord Howe Island</li><br/>
<abbr> </abbr><li class="flag _cat">Catalonia</li><br/>
<abbr> </abbr><li class="flag _LGBT">LGBT+ Pride</li><br/>
<!-- DO NOT REMOVE THIS LINE - AUTOMATIC INSERTION MARK -->

</ul>

</body>
Expand Down
7 changes: 7 additions & 0 deletions scaling_script.sh
@@ -0,0 +1,7 @@
for i in $(basename -s .png *.png); do
convert ${i}.png -scale 32x32 ${i}2.png
convert ${i}2.png -background none -gravity center -extent 32x32 ${i}32.png
convert ${i}.png -scale 16x16 ${i}2.png
convert ${i}2.png -background none -gravity center -extent 16x16 ${i}16.png
rm ${i}2.png
done
63 changes: 61 additions & 2 deletions stylesheets/flags16.css
Expand Up @@ -58,7 +58,7 @@
.f16 .cg{background-position:0 -912px;}
.f16 .cf{background-position:0 -928px;}
.f16 .cd{background-position:0 -944px;}
.f16 .ch{background-position:0 -960px;}
.f16 .ch{background-position:0 -4848px;}
.f16 .ci{background-position:0 -976px;}
.f16 .ck{background-position:0 -992px;}
.f16 .cl{background-position:0 -1008px;}
Expand Down Expand Up @@ -231,7 +231,7 @@
.f16 .us{background-position:0 -3664px;}
.f16 .uy{background-position:0 -3680px;}
.f16 .uz{background-position:0 -3696px;}
.f16 .va{background-position:0 -3712px;}
.f16 .va{background-position:0 -4864px;}
.f16 .vc{background-position:0 -3728px;}
.f16 .ve{background-position:0 -3744px;}
.f16 .vg{background-position:0 -3760px;}
Expand All @@ -246,3 +246,62 @@
.f16 .sx{background-position:0 -3904px;}
.f16 .cw{background-position:0 -3920px;}
.f16 .ss{background-position:0 -3936px;}
.f16 ._Klingon{background-position:0 -3952px;}
.f16 ._United_Federation_of_Planets{background-position:0 -3968px;}
.f16 ._Pirate{background-position:0 -3984px;}
.f16 ._Starfleet{background-position:0 -4000px;}
.f16 ._DOOP{background-position:0 -4016px;}
.f16 ._GoT_Arryn{background-position:0 -4032px;}
.f16 ._GoT_Baratheon{background-position:0 -4048px;}
.f16 ._GoT_Greyjoy{background-position:0 -4064px;}
.f16 ._GoT_Lannister{background-position:0 -4080px;}
.f16 ._GoT_Martell{background-position:0 -4096px;}
.f16 ._GoT_Stark{background-position:0 -4112px;}
.f16 ._GoT_Targaryen{background-position:0 -4128px;}
.f16 ._GoT_Tully{background-position:0 -4144px;}
.f16 ._GoT_Tyrell{background-position:0 -4160px;}
.f16 ._Esperanto{background-position:0 -4176px;}
.f16 .ct{background-position:0 -2048px;} /* same as .ki */
.f16 .ac{background-position:0 -4192px;}
.f16 .ic{background-position:0 -4208px;}
.f16 .cx{background-position:0 -4224px;}
.f16 .cc{background-position:0 -4240px;}
.f16 .an{background-position:0 -4256px;}
.f16 .cs{background-position:0 -4272px;}
.f16 .dg{background-position:0 -4304px;}
.f16 .gf{background-position:0 -4320px;}
.f16 .gs{background-position:0 -4336px;}
.f16 .hm{background-position:0 -544px;} /* same as .au */
.f16 .io{background-position:0 -4352px;}
.f16 .jt{background-position:0 -3664px;} /* same as .us */
.f16 .mi{background-position:0 -3664px;} /* same as .us */
.f16 .mp{background-position:0 -4368px;}
.f16 .nf{background-position:0 -4384px;}
.f16 .nu{background-position:0 -4400px;}
.f16 ._OGS{background-position:0 -4416px;}
.f16 .nu{background-position:0 -4432px;}
.f16 .cc{background-position:0 -4448px;}
.f16 .cx{background-position:0 -4464px;}
.f16 .gf{background-position:0 -4480px;}
.f16 .gs{background-position:0 -4496px;}
.f16 .io{background-position:0 -4512px;}
.f16 .mp{background-position:0 -4528px;}
.f16 .nf{background-position:0 -4544px;}
.f16 .pm{background-position:0 -4560px;}
.f16 .pn{background-position:0 -4576px;}
.f16 .tf{background-position:0 -4592px;}
.f16 .tk{background-position:0 -4608px;}
.f16 .wf{background-position:0 -4624px;}
.f16 ._GoT_Arryn{background-position:0 -4640px;}
.f16 ._GoT_Baratheon{background-position:0 -4656px;}
.f16 ._GoT_Greyjoy{background-position:0 -4672px;}
.f16 ._GoT_Lannister{background-position:0 -4688px;}
.f16 ._GoT_Martell{background-position:0 -4704px;}
.f16 ._GoT_Stark{background-position:0 -4720px;}
.f16 ._GoT_Targaryen{background-position:0 -4736px;}
.f16 ._GoT_Tully{background-position:0 -4752px;}
.f16 ._GoT_Tyrell{background-position:0 -4768px;}
.f16 ._Pirate{background-position:0 -4784px;}
.f16 ._Lord_Howe_Island{background-position:0 -4800px;}
.f16 ._cat{background-position:0 -4816px;}
.f16 ._LGBT{background-position:0 -4832px;}
66 changes: 62 additions & 4 deletions stylesheets/flags16.scss
Expand Up @@ -64,7 +64,7 @@
.cg{background-position:0 -912px;}
.cf{background-position:0 -928px;}
.cd{background-position:0 -944px;}
.ch{background-position:0 -960px;}
.ch{background-position:0 -4848px;}
.ci{background-position:0 -976px;}
.ck{background-position:0 -992px;}
.cl{background-position:0 -1008px;}
Expand Down Expand Up @@ -237,7 +237,7 @@
.us{background-position:0 -3664px;}
.uy{background-position:0 -3680px;}
.uz{background-position:0 -3696px;}
.va{background-position:0 -3712px;}
.va{background-position:0 -4864px;}
.vc{background-position:0 -3728px;}
.ve{background-position:0 -3744px;}
.vg{background-position:0 -3760px;}
Expand All @@ -252,5 +252,63 @@
.sx{background-position:0 -3904px;}
.cw{background-position:0 -3920px;}
.ss{background-position:0 -3936px;}

} // .f16
._Klingon{background-position:0 -3952px;}
._United_Federation_of_Planets{background-position:0 -3968px;}
._Pirate{background-position:0 -3984px;}
._Starfleet{background-position:0 -4000px;}
._DOOP{background-position:0 -4016px;}
._GoT_Arryn{background-position:0 -4032px;}
._GoT_Baratheon{background-position:0 -4048px;}
._GoT_Greyjoy{background-position:0 -4064px;}
._GoT_Lannister{background-position:0 -4080px;}
._GoT_Martell{background-position:0 -4096px;}
._GoT_Stark{background-position:0 -4112px;}
._GoT_Targaryen{background-position:0 -4128px;}
._GoT_Tully{background-position:0 -4144px;}
._GoT_Tyrell{background-position:0 -4160px;}
._Esperanto{background-position:0 -4176px;}
.ct{background-position:0 -2048px;} // same as .kiy
.ac{background-position:0 -4192px;}
.ic{background-position:0 -4208px;}
.cx{background-position:0 -4224px;}
.cc{background-position:0 -4240px;}
.an{background-position:0 -4256px;}
.cs{background-position:0 -4272px;}
.dg{background-position:0 -4304px;}
.gf{background-position:0 -4320px;}
.gs{background-position:0 -4336px;}
.hm{background-position:0 -544px;} // same as .au
.io{background-position:0 -4352px;}
.jt{background-position:0 -3664px;} /* same as .us */
.mi{background-position:0 -3664px;} /* same as .us */
.mp{background-position:0 -4368px;}
.nf{background-position:0 -4384px;}
.nu{background-position:0 -4400px;}
._OGS{background-position:0 -4416px;}
.nu{background-position:0 -4432px;}
.cc{background-position:0 -4448px;}
.cx{background-position:0 -4464px;}
.gf{background-position:0 -4480px;}
.gs{background-position:0 -4496px;}
.io{background-position:0 -4512px;}
.mp{background-position:0 -4528px;}
.nf{background-position:0 -4544px;}
.pm{background-position:0 -4560px;}
.pn{background-position:0 -4576px;}
.tf{background-position:0 -4592px;}
.tk{background-position:0 -4608px;}
.wf{background-position:0 -4624px;}
._GoT_Arryn{background-position:0 -4640px;}
._GoT_Baratheon{background-position:0 -4656px;}
._GoT_Greyjoy{background-position:0 -4672px;}
._GoT_Lannister{background-position:0 -4688px;}
._GoT_Martell{background-position:0 -4704px;}
._GoT_Stark{background-position:0 -4720px;}
._GoT_Targaryen{background-position:0 -4736px;}
._GoT_Tully{background-position:0 -4752px;}
._GoT_Tyrell{background-position:0 -4768px;}
._Pirate{background-position:0 -4784px;}
._Lord_Howe_Island{background-position:0 -4800px;}
._cat{background-position:0 -4816px;}
._LGBT{background-position:0 -4832px;}
} // .f16 - DO NOT REMOVE THIS LINE