タイトル
<?php
function svgstart(){
header('Content-type: image/svg+xml');
print <<<EOD1
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" id="layer1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px"
viewBox="0 0 595.3 841.9"
style="enable-background:new 0 0 595.3 841.9;"
xml:space="preserve">
<style type="text/css">
.mfont{font-size:18pt;text-anchor:middle;}
.m2font{font-size:8px;text-anchor:middle;}
.m3font{font-size:9px;}
.wfont{font-size:4pt;text-anchor:middle;}
.dfont{font-size:12pt;text-anchor:middle;fill:white;font-family:Times;}
.dfont2{font-size:8pt;text-anchor:middle;fill:white;}
.c01{fill:#222222;}
.c02{fill:#A1B2DB;}
.c03{fill:#F29A5A;}
.c04{fill:#ED7235;}
</style>
EOD1;
}
function svgend() {
print "</svg>\n";
}
function svgmonth($nen,$month,$bx=0,$by=40,$color=0) {
$holi1 = array(
array(11,3,"文化の日"),
array(11,23,"勤労感謝の日"),
array(12,23,"天皇誕生日"),
array(1,1,"元日"),
array(2,11,"建国記念日"),
array(4,29,"昭和の日"),
array(5,3,"憲法記念日"),
array(5,4,"みどりの日"),
array(5,5,"こどもの日"),
array(8,11,"山の日"),
);
$holi2 = array(
array(1,2,"成人式"),
array(7,3,"海の日"),
array(9,3,"敬老の日"),
array(10,2,"体育の日"),
);
if($month==3) {
$n=(int)(20.8431+0.242194*($nen-1980))-(int)(($nen-1980)/4);
array_push($holi1,array(3,$n,"春分の日"));
}
if($month==9) {
$n=(int)(23.2488+0.242194*($nen-1980))-(int)(($nen-1980)/4);
array_push($holi1,array(9,$n,"秋分の日"));
$stday = new DateTime($nen.'-'.$month.'-'.$n);
$w = (int)$stday->format('w');
if($w==3) {
array_push($holi1,array(9,$n-1,"国民の休日"));
}
}
$stday = new DateTime($nen.'-'.$month.'-1');
$stweek = (int)$stday->format('w'); // 1日の曜日
$days = (int)$stday->format('t'); // 月の日数
$weeks=array("SUN","MON","TUE","WED","THU","FRI","SAT");
$months = array('January','February','March','April','May','June','July','August'
,'September','October','Nobember','December');
print "<g transform=\"translate({$bx},{$by})\">\n"; // 月の始まり
$wn = 0; // 何週目
$w = $stweek; //スタートの曜日
$px = 0; // 日のX座標
$py = 0; // 日のY座標
$c = 1; // 色
$mess = '';
$furi = false;
$s = $months[$month-1];
print "<text class=\"mfont c01\" x=\"25\" y=\"50\">{$month}</text>\n";
print "<text class=\"m2font c01\" x=\"25\" y=\"60\">{$s}</text>\n";
print "<g transform=\"translate(45,30)\">\n"; // 月の数字の部分の基点
for($i=1;$i<=$days;$i++) {
if($w==0)
$c = 3;
elseif($w==6)
$c = 2;
else
$c = 1;
if($furi) { // 振替休日
$c = 3;
$furi = false;
$mess.="{$i}日振替休日 ";
}
foreach($holi1 as $h) { // 固定祝日
if($h[0]==$month && $h[1]==$i) {
$c = 4;
if($w==0) $furi=true;
$mess.="{$i}日{$h[2]} ";
}
}
$wn2 = (int)(($i+6)/7);
foreach($holi2 as $h) { // 月曜日の祝日
if($w==1 && $h[0]==$month && $h[1]==$wn2) {
$c = 4;
$mess.="{$i}日{$h[2]} ";
}
}
$week = $weeks[$w];
print <<<LINE1
<g transform="translate({$px},0)">
<text class="dfont c0{$c}" x="12" y="16" letter-spacing="-2">{$i}</text>
<text class="wfont c0{$c}" x="12" y="25">{$week}</text>
</g>\n
LINE1;
$w++;
$px += 17;
if($w>6) {
$w = 0;
}
}
print "</g>\n"; //月の数字の部分の終わり
if(!empty($mess)) {
$py = 60;
print "<text class=\"m3font c04\" x=\"50\" y=\"70\">{$mess}</text>\n";
}
print "</g>\n"; // 月の終わり
}
// Main Program
svgstart();
$px=30;$x=0;
$py=30;
$color=0;
$nen = $_GET['nen']+0;
$month = $_GET['month']+0;
if($nen==0) $nen=2017;
if($month==0) $month=12;
svgmonth($nen,$month,0,750);
svgend();