Exemplo 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);
             }
         }
     }
 }
Exemplo n.º 2
0
<?php

use Onephile\Img;
// configure
Img::configure(array('base_dir' => IMG_BASE_DIR, 'output_dir' => 'tmp/'));
// create img from path relative to base_dir
$Img = new Img('http://cdn.morguefile.com/imageData/public/files/e/ecerroni/preview/fldr_2008_11_13/file0001973007888.jpg');
// smart cropping scales and tries to find the best area to crop
$result = $Img->thumb(array('width' => 120, 'height' => 120, 'smartcrop' => true));
// output original image
echo '<img src="' . $Img->getSrc() . '">';
// output the newly saved image
echo $result ? '<img src="' . $result . '">' : $Img->getError();