PHP(> = 5.4)、199 197バイト
(さらにゴルフで2バイト)
<?$s=strlen(file_get_contents($argv[1])).'';echo strtr([waning_crescent,waning_gibbous,new_moon,0,waxing_crescent,waxing_gibbous,full_moon,first_quarter,third_quarter][($s[0]+$s[3])%11-2],'_',' ');
実行するには:
php -d error_reporting=0 -d short_open_tag=1 <filename> <image_path>
例:
php -d error_reporting=0 -d short_open_tag=1 lunar_phase.php https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Moon_phase_6.svg/240px-Moon_phase_6.svg.png
ノート:
- この
-d error_reporting=0
オプションは、通知/警告を出力しないために使用されます。
-d short_open_tag=1
短いタグを許可するために必要とされます。
https
上記の例のようなURL を使用している場合は、OpenSSLも有効にする必要があります。
どうやって?
次の式でファイルサイズ(バイト)を取得し、その固有の数値を作成します。
((<first_bytes_digit> + <fourth_bytes_digit>) % 11) - 2
この数式は、0から8までの数を生成し、3だけを欠落させます。
┌─────────────────┬───────┬─────────┬─────┬────────────────────────┐
│ Phase │ Bytes │ 1st+4th │ %11 │ -2 (position in array) │
├─────────────────┼───────┼─────────┼─────┼────────────────────────┤
│ new moon │ 3451 │ 3+1=4 │ 4 │ 2 │
│ waxing crescent │ 6430 │ 6+0=6 │ 6 │ 4 │
│ first quarter │ 5144 │ 5+4=9 │ 9 │ 7 │
│ waxing gibbous │ 7070 │ 7+0=7 │ 7 │ 5 │
│ full moon │ 5283 │ 5+3=8 │ 8 │ 6 │
│ waning gibbous │ 7067 │ 7+7=14 │ 3 │ 1 │
│ third quarter │ 4976 │ 4+6=10 │ 10 │ 8 │
│ waning crescent │ 6337 │ 6+7=13 │ 2 │ 0 │
└─────────────────┴───────┴─────────┴─────┴────────────────────────┘
以前のアプローチ:
PHP(> = 5.4)、251バイト
<?foreach([4,8,16,20]as$w){$a+=imagecolorat(imagecreatefrompng($argv[1]),$w*10,120)>1e7;$a&&$w<5?$b=-2:0;}$x=explode('_','full moon_waning gibbous_third quarter_waning crescent_new moon_waxing crescent_first quarter_waxing gibbous');echo$x[$a*++$b+4];
実行するには:
php -d error_reporting=0 -d short_open_tag=1 <filename> <image_path>
例:
php -d error_reporting=0 -d short_open_tag=1 lunar_phase.php https://upload.wikimedia.org/wikipedia/commons/thumb/c/c9/Moon_phase_6.svg/240px-Moon_phase_6.svg.png
ノート:
- この
-d error_reporting=0
オプションは、通知/警告を出力しないために使用されます。
-d short_open_tag=1
短いタグを許可するために必要とされます。
- PHPにはGDが必要であり、有効にする必要があります。
https
上記の例のようなURL を使用している場合は、OpenSSLも有効にする必要があります。
どうやって?
画像における4つの画素の色をチェックし40,120
、80,120
、160,120
および200,120
それらの色からムーン位相を決定します。