User:3247's Image Wizard/Scripts/mk iso639.pl

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
 #!/usr/bin/perl
 
 open FILES, ">files.txt";
 
 sub width ($) {
   my $w = 0; my($l,$r) = (0,0);
   foreach my $l (split //, $_[0]) {
     $w++ if $l =~ m/[mw]/;
     $w-- if $l =~ m/[fijlt]/;
     $w+=2;
   }
 
   $l = 1 if $_[0] =~ m/^[bhkj]/;
   $r = 1 if $_[0] =~ m/[gql]$/;
 
   $w += .5 if $l && $r;
 
   return ($w, $l ? ($r ? 0 : 5) : ($r ? -5 : 0));
 }
 
 foreach(@ARGV) {
   my $f = lc $_; my $F = uc $f;
   open FILE, ">ISO 639-1 Icon $f.svg";
 
   print FILE '<?xml version="1.0" encoding="UTF-8" standalone="no"?>',"\n";
   print FILE '<svg xmlns="http://www.w3.org/2000/svg" width="400" height="180">',"\n";
   print FILE '<path fill="#0000C8" d="M21.394289 0a200 200 0 0 0 0 180L67.712434 180a160 160 0 0 1 0 -180ZM330.228757 0a160 160 0 0 1 0 180L378.605711 180a200 200 0 0 0 0 -180Z" />',"\n";
   print FILE '<path fill="navy" d="M87.754733 15a135 135 0 0 0 0 150L119.532615 165a119 119 0 0 1 0 -150ZM280.467385 15a110 110 0 0 1 0 150L312.245267 165a135 135 0 0 0 0 -150Z" />',"\n";
 
   my ($w,$s) = width $f; $w = 4 if $w <= 4;
   printf FILE '<text x="%d" y="141" font-size="150" fill="navy" font-family="Helvetica,Arial,sans-serif" font-weight="bold"', (200 + $s) * $w / 4;
   printf FILE ' transform="scale(%01.2f 1)"', 4/$w if $w > 4;
   print FILE ' text-anchor="middle">', $f, '</text>',"\n";
   print FILE '</svg>',"\n";
 
   print FILES ">ISO 639 Icon $f.svg\n";
   print FILES "{{Information\n";
   print FILES "|Description = {{en|Language icon for ISO 631 language code '''$F'''}}\n";
   print FILES "|Date = {{subst:CURRENTYEAR}}-{{subst:CURRENTMONTH}}-{{subst:CURRENTDAY2}}\n";
   print FILES "|Source = created with [[:User:3247's Image Wizard/Scripts/mk_iso639.pl|mk_iso639.pl]]\n";
   print FILES "|Permission = see below\n";
   print FILES "|Author = Claus Färber ([[User:3247|]]); based on bitmap by [[User:Nataraja|Nataraja]] and SVG by [[user:Shazz|Shazz]]\n";
   print FILES "}}\n\n";
   print FILES "==License==\n";
   print FILES "{{GFDL}}\n";
   print FILES "[[Category:Icons ISO 639|$f]]\n";
 }


GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled GNU Free Documentation License.
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license.
You are free:
  • to share – to copy, distribute and transmit the work
  • to remix – to adapt the work
Under the following conditions:
  • attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
  • share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This licensing tag was added to this file as part of the GFDL licensing update.