#!/usr/bin/env php $image) { if (!in_array($image, $seen) && preg_match('/\.(gif|ico|png|jpg|jpeg)$/', $image)) { $filepath = pathinfo($file, PATHINFO_DIRNAME) . "/$image"; if (file_exists($filepath)) { $sum = substr(md5_file($filepath), 0, 4) . '.' . filesize($filepath); } else { print "ERROR: Missing image: $filepath\n"; continue; } $content = str_replace($matches[0][$idx], "url($image?v=$sum)", $content); } $seen[] = $image; } file_put_contents($file, $content); } } function get_files($dir) { $files = []; $dh = opendir($dir); while ($file = readdir($dh)) { if (preg_match('/^(.+)\.min\.css$/', $file, $m)) { $files[] = "$dir/$file"; } else if ($file[0] != '.' && is_dir("$dir/$file")) { foreach (get_files("$dir/$file") as $f) { $files[] = $f; } } } closedir($dh); return $files; }