Created
June 30, 2016 06:10
-
-
Save yoya/34d09f4692c6a7deedad8b748d989ff0 to your computer and use it in GitHub Desktop.
test image generation (NG)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cramp255($v) { | |
if ($v < 0) { | |
return 0; | |
} | |
return ($v<=255)?$v:255; | |
} | |
function getRGBA($x, $y, $width, $height) { | |
$divX = 3000; $divY = 3000; | |
$xRatio = $x / $width; | |
$yRatio = $y / $height; | |
$xx = $xRatio - 0.5; | |
$yy = $yRatio - 0.5; | |
$dRatio = sqrt($xx * $xx * $divX + $yy * $yy * $divY); | |
$l = sin($dRatio * 2 * M_PI); | |
$r = 255 * $l; | |
$g = 255 * sin($xRatio * 2 * M_PI * 4) * $l; | |
$b = 255 * sin($yRatio * 2 * M_PI * 4) * $l; | |
$a = 0; | |
return [cramp255($r), cramp255($g), cramp255($b), cramp255($a)]; | |
} | |
if ($argc < 3) { | |
echo "Usage: php testimageNG.php <width> <height>".PHP_EOL; | |
echo "ex) php testimageNG.php 320 320".PHP_EOL; | |
exit (1); | |
} | |
list($prog, $width, $height) = $argv; | |
$im = imagecreatetruecolor($width, $height); | |
for ($y = 0 ; $y < $height ; $y++) { | |
for ($x = 0 ; $x < $width ; $x++) { | |
list($r, $g, $b, $a) = getRGBA($x, $y, $width, $height); | |
$c = imagecolorallocatealpha($im, $r, $g, $b, $a); | |
imagesetpixel($im, $x, $y, $c); | |
} | |
} | |
// imagesavealpha($im, true); | |
imagepng($im); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment