/** * Expands a input argument to a file of lists matching certain extensions * * @param $in input argument (full path to file/directory, array with multiple entries) * @param $haystack array describing allowed strings, eg: test*.php, *.jpg, test*, *test * @return array with filenames */ function expand_arg_files($in, $haystack = array()) { if (is_array($in)) { throw new \Exception('FIXME be recursive'); /* $res = array(); foreach ($in as $f) if (in_array( file_suffix($f), $haystack)) $res[] = $f; return $res;*/ } if (is_file($in)) { if (arg_match($in, $haystack)) { return array(realpath($in)); } else { return array(); } } if (is_dir($in)) { return dir_get_matches($in, $haystack, '', true, false); } /* if (strpos($in, "\n") !== false) { if ($haystack) throw new \Exception ('XXX respect $haystack'); return explode("\n", trim($in)); // newline-separated list of filenames with full path }*/ // expand from $in = "/media/downloads/part-of-name*.avi" if (is_string($in) && !$haystack) { return dir_get_matches(dirname($in), array(basename($in))); } throw new \Exception('Unknown input: ' . $in); }
<?php namespace cd; set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../core/'); require_once 'IconReader.php'; require_once 'files.php'; $base_dir = '/devel/core_dev/trunk/tests/ICO_files/ico/'; $files = dir_get_matches($base_dir, array('*.ico')); d($files); /* $files = array( '16x16x1-1.ico', //XXXX 1 bpp unsupported '16x16x4-1.ico', '32x32x4-1.ico', '32x32x4-2.ico', 'multi-1.ico', 'multi-3.ico', 'vista_icon.ico', // from Spotify.exe, has PNG resource. XXX nautilus 2.32 dont show thumbnail but should be fixed 'minor-bug-1.ico', //first 2 images have green borders where it should be transparency (???) "icotool" from icoutils package does the same ); */ $out_dir = 'ico_png/'; if (!is_dir($out_dir)) { mkdir($out_dir); } foreach ($files as $in) { echo 'Reading ' . $in . ":\n"; print_r(IconReader::listLmages($base_dir . $in)); foreach (IconReader::getImages($base_dir . $in) as $idx => $i) { imagepng($i, $out_dir . basename($in) . '-' . ($idx + 1) . '.png');
public function test3() { // verifies current directory holds at least 50 tests $tests = dir_get_matches('.', array('*Test.php')); $this->assertGreaterThan(50, count($tests)); }
<?php /** * $Id$ */ die; set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__) . '/../../core/'); require_once 'core.php'; $out_sprite = 'sprite.png'; if (file_exists($out_sprite)) { unlink($out_sprite); } $sprites = dir_get_matches('./', array('*.png')); $use_width = 16; $use_height = 11; foreach ($sprites as $f) { list($width, $height) = getimagesize($f); if ($use_width && $width > $use_width) { throw new \Exception('wrong width: ' . $width . ' in ' . $f); } if ($height != $use_height) { throw new \Exception('wrong height: ' . $height . ' in ' . $f); } } $im = imagecreatetruecolor($use_width, $use_height * count($sprites)); //XXXX how to enable transparent pixel without using full alpha channel of png? this adds 3K of size to test png imagesavealpha($im, true); imagealphablending($im, false); // make background transparent $back = imagecolorallocatealpha($im, 255, 255, 255, 127); imagefilledrectangle($im, 0, 0, imagesx($im) - 1, imagesy($im) - 1, $back);