diff --git a/cache/.gitignore b/cache/.gitignore new file mode 100644 index 0000000..00f63ad --- /dev/null +++ b/cache/.gitignore @@ -0,0 +1,3 @@ +# This directory is used to cache fusion as PNG files +# This way, they are only generated once, saving CPU and RAM on the server, at the expense of disk space +# Remember to delete the corresponding fusions in this directory if you make any change to an image in the /ponies directory, otherwise the changes won't be reflected diff --git a/fusion.php b/fusion.php index f205c1b..540b14e 100644 --- a/fusion.php +++ b/fusion.php @@ -1,55 +1,82 @@ 0, 'y' => 0, 'width' => imagesx($from), 'height' => imagesy($from) - 1]); + + if(!$debug && !$fromCli) + { + header('Content-Type: image/png'); + imagepng($from); + } + + // Save fusion to cache + imagepng($from, $cacheFilename); + + imagedestroy($to); } -// Retain transparency -imagealphablending($from, false); -imagesavealpha($from, true); -imagefill($from, 0, 0, imagecolorallocatealpha($from, 255, 255, 255, 127)); - -// Crop 1px from bottom to avoid showing swatch -$from = imagecrop($from, ['x' => 0, 'y' => 0, 'width' => imagesx($from), 'height' => imagesy($from) - 1]); - -if(!$debug) +// Don't run the function if we're running from the command line +if (php_sapi_name() !== 'cli') { - header('Content-Type: image/png'); - imagepng($from); + $getFrom = $_GET["from"]; + $getTo = $_GET["to"]; + makeFusion($getFrom, $getTo, FALSE); } -imagedestroy($to); ?> \ No newline at end of file diff --git a/generate_all.php b/generate_all.php new file mode 100644 index 0000000..b77e3df --- /dev/null +++ b/generate_all.php @@ -0,0 +1,42 @@ + $properties) +{ + if(strpos($id, "break") === FALSE) + $totalPonies++; +} + +$totalFusions = $totalPonies * $totalPonies; + +$i = 0; +foreach($ponies as $id => $properties) +{ + if(strpos($id, "break") === FALSE) + { + foreach($ponies as $idSecond => $propertiesSecond) + { + if(strpos($idSecond, "break") === FALSE) + { + $i++; + $percentage = sprintf("%3d", floor(($i / $totalFusions) * 100)); + echo "($percentage%) [$i/$totalFusions] $id + $idSecond\n"; + makeFusion($id, $idSecond, TRUE); + sleep(1); + } + } + } +} +?> \ No newline at end of file