From 4f36b72f5c69e0ae1917de4012286366ca29c393 Mon Sep 17 00:00:00 2001 From: Christian Seiler Date: Tue, 30 Jun 2026 18:38:22 +0200 Subject: [PATCH] Add animation extractor script --- php/extract_animation.php | 58 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 php/extract_animation.php diff --git a/php/extract_animation.php b/php/extract_animation.php new file mode 100644 index 0000000..dd4726f --- /dev/null +++ b/php/extract_animation.php @@ -0,0 +1,58 @@ +sections as $section) { + for ($i = 0; $i < $section->elementCount(); ++$i) { + $element = $section->elementAt($i); + if ($element->elementType() == monoformat\ElementType::Animation) { + array_push($animations, $element); + } + } +} + +if ($index < 0 || $index >= count($animations)) { + $n = count($animations); + $nm1 = $n - 1; + fwrite(STDERR, "$argv[0]: the animation file contains $n animations, index $index is invalid (must be 0 .. $nm1)\n"); + exit(2); +} + +$animation = $animations[$index]; +$height = $animation->height(); +$width = $animation->width(); + +$nFrames = $animation->numberOfFrames(); +for ($f = 0; $f < $nFrames; ++$f) { + $outfile = sprintf("%s_%04d.png", $outprefix, $f); + print("Writing $outfile...\n"); + $input = $animation->image($f); + $image = imagecreatetruecolor($width, $height); + $bg = imagecolorallocate($image, 0, 0, 0); + $fg = imagecolorallocate($image, 255, 255, 255); + for ($y = 0; $y < $height; ++$y) { + for ($x = 0; $x < $width; ++$x) { + $i = $y * $width + $x; + if ($input[$i]) { + imagesetpixel($image, $x, $y, $fg); + } else { + imagesetpixel($image, $x, $y, $bg); + } + } + } + imagepng($image, $outfile); +} + +?>