Skip to content

Instantly share code, notes, and snippets.

@hugowetterberg
Created September 21, 2009 13:09
Show Gist options
  • Save hugowetterberg/190235 to your computer and use it in GitHub Desktop.
Save hugowetterberg/190235 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
$content = file_get_contents($argv[1]);
function invert_color($matches) {
$r = 255 - intval(substr($matches[1], 0, 2), 16);
$g = 255 - intval(substr($matches[1], 2, 2), 16);
$b = 255 - intval(substr($matches[1], 4, 2), 16);
$a = isset($matches[2]) ? $matches[2] : '';
return sprintf("#%02x%02x%02x%s", $r, $g, $b, $a);
}
$inverted = preg_replace_callback('@\#([a-f0-9]{6})([a-f0-9]{2})?@i', 'invert_color', $content);
file_put_contents($argv[1] . '.inv', $inverted);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment