Jump to content

icyliquid

Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by icyliquid

  1. I\'m on OS X and couldn\'t find a fast way to convert all my PNGs to 32 bit. So I wrote this quick PHP script. It should actually work in windows too, but who knows (not tested)? Hope it works for you guys Instructions [li]Save this code to a file called convert.php. I suggest putting it in your home folder: /Users/yourusername/[/li] [li]Open a terminal window and navigate to the folder containing convert.php[/li] [li]Run convert.php with the path to your KSP/Parts/ folder as the argument[/li] [li]Done![/li] Example Code #!/usr/bin/php <?php // Folder is first argument $Folder = $argv[1]; if (!file_exists($Folder) || !is_dir($Folder)) exit(1); $ConvertFiles = array(); FindPNGs($Folder, $ConvertFiles); foreach ($ConvertFiles as $ConvertFile) ConvertPNG($ConvertFile); function FindPNGs($Folder, &$ConvertFiles) { $Files = scandir($Folder); foreach ($Files as $File) { if (in_array($File, array(\'.\',\'..\'))) continue; $RealFile = CombinePaths(array($Folder, $File)); if (is_dir($RealFile)) { FindPNGs($RealFile, $ConvertFiles); continue; } if (substr($File, -3) == \'png\') { $ConvertFiles[] = $RealFile; } } } function ConvertPNG($PNGFile) { echo ' > converting {$PNGFile}\n'; $PngImage = imagecreatefrompng($PNGFile); imagealphablending($PngImage, FALSE); imagesavealpha($PngImage, TRUE); imagepng($PngImage, $PNGFile); } function CombinePaths($Paths, $Delimiter = \'/\') { if (is_array($Paths)) { $MungedPath = implode($Delimiter, $Paths); $MungedPath = str_replace(array($Delimiter.$Delimiter.$Delimiter, $Delimiter.$Delimiter), array($Delimiter, $Delimiter), $MungedPath); return str_replace(array(\'http:/\', \'https:/\'), array(\'[url]http://\'[/url], \'[url]https://\'[/url]), $MungedPath); } else { return $Paths; } } ?>
×
×
  • Create New...