#!/usr/bin/php

<?php

	$handle=opendir(".");

	if (!$handle)
	{
		echo ("Invalid directory\n");
		exit();
	}

	while (($file = readdir($handle)) !== false)
	{
		$pos = strpos($file, ".png");
		if ($pos !== false)
		{
			$command = sprintf("convert -colors 256 $file $file");
			echo "$command\n";
			system($command);
		}
	}

	closedir($handle);

	echo "Done.\n";
?>
