Ejemplo n.º 1
0
 public function testThumbSizingWithConfig()
 {
     $config_defaults = self::$configDefaults;
     $config = array('base_dir' => __DIR__ . '/', 'output_dir' => 'tmp/', 'upscale' => true, 'sizes' => array('Medium' => array('width' => 50, 'height' => 50, 'upscale' => false), 'small' => array('width' => 20, 'height' => 20, 'crop' => false), 'xtra-small' => array('width' => 10, 'height' => 10)));
     Img::configure($config);
     foreach (array('jpg', 'png', 'gif') as $ext) {
         $src = self::$imgs[$ext]['file'];
         $Img = new Img($src);
         foreach ($config['sizes'] as $size => $size_data) {
             $thumb_path = $Img->thumb($size);
             $this->assertTrue(strlen($thumb_path) > 0, $Img->getError());
             $filebase = $Img->getInfo('filebase');
             $this->assertTrue(is_file($config['base_dir'] . $thumb_path), 'Not a file: ' . $config['base_dir'] . $thumb_path);
             $expected_thumb_path = $config['output_dir'] . $filebase . '-' . $size . '.' . $ext;
             $this->assertEquals($expected_thumb_path, $thumb_path);
             $Thumb = new Img($thumb_path);
             $this->assertEquals($thumb_path, $Thumb->getSrc());
             $this->assertEquals($config['base_dir'] . $thumb_path, $Thumb->getPath());
             $crop = isset($size_data['crop']) ? $size_data['crop'] : $Thumb->getConfig('crop');
             $upscale = isset($size_data['upscale']) ? $size_data['upscale'] : $Thumb->getConfig('upscale');
             if ($crop && $upscale) {
                 $this->assertEquals($size_data['width'], $Thumb->getInfo('width'));
                 $this->assertEquals($size_data['height'], $Thumb->getInfo('height'));
             }
             // cleanup
             if (is_file($config['base_dir'] . $thumb_path)) {
                 unlink($config['base_dir'] . $thumb_path);
             }
         }
     }
 }