[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/imagekit/tests/cases/ -> lmbImageLibraryTestBase.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  abstract class lmbImageLibraryTestBase extends UnitTestCase
  11  {
  12    var $library = null;
  13    var $input_file = '';
  14    var $output_file = '';
  15  
  16    function setUp()
  17    {
  18      $this->input_file = dirname(__FILE__) . '/images/input.jpg';
  19      $this->output_file = LIMB_VAR_DIR . '/output.jpg';
  20  
  21      if(!file_exists($this->output_file))
  22        touch($this->output_file);
  23  
  24      $input_type = 'jpeg';
  25      $output_type = 'jpeg';
  26      $this->library->setInputFile($this->input_file, $input_type);
  27      $this->library->setOutputFile($this->output_file, $output_type);
  28    }
  29  
  30    function tearDown()
  31    {
  32      if(file_exists($this->output_file))
  33        unlink($this->output_file);
  34    }
  35  
  36    function testInstalled()
  37    {
  38      $this->assertTrue($this->library->isLibraryInstalled());
  39    }
  40  
  41    function testResizeByMaxDimension()
  42    {
  43      $max_dimension = 200;
  44      $params = array('max_dimension' => $max_dimension);
  45      $this->library->resize($params);
  46      $this->library->commit();
  47  
  48      $info1 = getimagesize($this->input_file);
  49      $info2 = getimagesize($this->output_file);
  50      if ($info1[0] > $info1[1])
  51        $this->assertEqual($info2[0], $max_dimension);
  52      else
  53        $this->assertEqual($info2[1], $max_dimension);
  54    }
  55  
  56    function testResizeByScaleFactor()
  57    {
  58      $scale_factor = 2;
  59      $params = array('scale_factor' => $scale_factor);
  60      $this->library->resize($params);
  61      $this->library->commit();
  62  
  63      $info1 = getimagesize($this->input_file);
  64      $info2 = getimagesize($this->output_file);
  65      $this->assertEqual(floor($info1[0] * $scale_factor), $info2[0]);
  66      $this->assertEqual(floor($info1[1] * $scale_factor), $info2[1]);
  67    }
  68  
  69    function testResizeByXyScale()
  70    {
  71      $info1 = getimagesize($this->input_file);
  72      $xscale = 2;
  73      $yscale = 1.5;
  74  
  75      $params = array('xscale' => $xscale, 'preserve_aspect_ratio' => true);
  76      $this->library->resize($params);
  77      $this->library->commit();
  78  
  79      $info2 = getimagesize($this->output_file);
  80      $this->assertEqual(floor($info1[0] * $xscale), $info2[0]);
  81      $this->assertEqual(floor($info1[1] * $xscale), $info2[1]);
  82  
  83      $params = array('yscale' => $yscale, 'preserve_aspect_ratio' => true);
  84      $this->library->resize($params);
  85      $this->library->commit();
  86  
  87      $info2 = getimagesize($this->output_file);
  88      $this->assertEqual(floor($info1[0] * $yscale), $info2[0]);
  89      $this->assertEqual(floor($info1[1] * $yscale), $info2[1]);
  90  
  91      $params = array('xscale' => $xscale, 'yscale' => $yscale);
  92      $this->library->resize($params);
  93      $this->library->commit();
  94  
  95      $info2 = getimagesize($this->output_file);
  96      $this->assertEqual(floor($info1[0] * $xscale), $info2[0]);
  97      $this->assertEqual(floor($info1[1] * $yscale), $info2[1]);
  98    }
  99  
 100    function testResizeByWidthHeight()
 101    {
 102      $info1 = getimagesize($this->input_file);
 103      $width = 200;
 104      $height = 300;
 105  
 106      $params = array('width' => $width, 'preserve_aspect_ratio' => true);
 107      $this->library->resize($params);
 108      $this->library->commit();
 109  
 110      $info2 = getimagesize($this->output_file);
 111      $this->assertEqual($info2[0], $width);
 112      $this->assertEqual($info2[1], floor($info1[1] * $width / $info1[0]));
 113  
 114      $params = array('height' => $height, 'preserve_aspect_ratio' => true);
 115      $this->library->resize($params);
 116      $this->library->commit();
 117  
 118      $info2 = getimagesize($this->output_file);
 119      $this->assertEqual($info2[0], floor($info1[0] * $height / $info1[1]));
 120      $this->assertEqual($info2[1], $height);
 121  
 122      $params = array('width' => $width, 'height' => $height);
 123      $this->library->resize($params);
 124      $this->library->commit();
 125  
 126      $info2 = getimagesize($this->output_file);
 127      $this->assertEqual($info2[0], $width);
 128      $this->assertEqual($info2[1], $height);
 129    }
 130  
 131  /*  function test_rotate()

 132    {

 133      return;

 134      $angle = 30;

 135  

 136      $this->library->rotate($angle, '000000');

 137      $this->library->commit();

 138  

 139      $this->assertEqual(filesize($this->output_file), $this->rotated_size);

 140      clearstatcache();

 141    }

 142  */
 143  
 144    function testFlip()
 145    {
 146      $info1 = getimagesize($this->input_file);
 147  
 148      $this->library->flip(LIMB_IMAGE_LIBRARY_FLIP_HORIZONTAL);
 149      $this->library->commit();
 150  
 151      $info2 = getimagesize($this->output_file);
 152      $this->assertEqual($info1[0], $info2[0]);
 153      $this->assertEqual($info1[1], $info2[1]);
 154  //      $this->assertEqual(filesize($this->output_file), $this->hflipped_size);

 155      clearstatcache();
 156  
 157      $this->library->flip(LIMB_IMAGE_LIBRARY_FLIP_VERTICAL);
 158      $this->library->commit();
 159  
 160      $info2 = getimagesize($this->output_file);
 161      $this->assertEqual($info1[0], $info2[0]);
 162      $this->assertEqual($info1[1], $info2[1]);
 163  //      $this->assertEqual(filesize($this->output_file), $this->wflipped_size);

 164      clearstatcache();
 165    }
 166  
 167    function testCutInside()
 168    {
 169      $info1 = getimagesize($this->input_file);
 170      $bgcolor = '000000';
 171  
 172      $x = 10;
 173      $y = 10;
 174      $w = 50;
 175      $h = 50;
 176  
 177      //$this->library->rotate(30, $bgcolor);

 178      $this->library->cut($x, $y, $w, $h, $bgcolor);
 179      $this->library->commit();
 180  
 181      $info2 = getimagesize($this->output_file);
 182  
 183    if(!file_exists($this->output_file))
 184      echo $this->output_file . '<br>';
 185  
 186      $this->assertEqual($info2[0], $w);
 187      $this->assertEqual($info2[1], $h);
 188  //      $this->assertEqual(filesize($this->output_file), $this->cutted_size1);

 189      clearstatcache();
 190    }
 191  
 192    function testCutOutside()
 193    {
 194      $info1 = getimagesize($this->input_file);
 195      $bgcolor = '000000';
 196  
 197      $x = -10;
 198      $y = -10;
 199      $w = 200;
 200      $h = 200;
 201  
 202      //$this->library->rotate(30, $bgcolor);

 203      $this->library->cut($x, $y, $w, $h, $bgcolor);
 204      $this->library->commit();
 205  
 206      $info2 = getimagesize($this->output_file);
 207      $this->assertEqual($info2[0], $w);
 208      $this->assertEqual($info2[1], $h);
 209  //      $this->assertEqual(filesize($this->output_file), $this->cutted_size2);

 210      clearstatcache();
 211    }
 212  
 213    function testCutLeftUp()
 214    {
 215      $info1 = getimagesize($this->input_file);
 216      $bgcolor = '000000';
 217  
 218      $x = -10;
 219      $y = -10;
 220      $w = 50;
 221      $h = 50;
 222  
 223      $this->library->cut($x, $y, $w, $h, $bgcolor);
 224      $this->library->commit();
 225  
 226      $info2 = getimagesize($this->output_file);
 227      $this->assertEqual($info2[0], $w);
 228      $this->assertEqual($info2[1], $h);
 229  //      $this->assertEqual(filesize($this->output_file), $this->cutted_size3);

 230      clearstatcache();
 231    }
 232  
 233    function testCutRightDown()
 234    {
 235      $info1 = getimagesize($this->input_file);
 236      $bgcolor = '000000';
 237  
 238      $x = 50;
 239      $y = 50;
 240      $w = 100;
 241      $h = 100;
 242  
 243      $this->library->cut($x, $y, $w, $h, $bgcolor);
 244      $this->library->commit();
 245  
 246      $info2 = getimagesize($this->output_file);
 247      $this->assertEqual($info2[0], $w);
 248      $this->assertEqual($info2[1], $h);
 249  //      $this->assertEqual(filesize($this->output_file), $this->cutted_size4);

 250      clearstatcache();
 251    }
 252  }
 253  ?>


Generated: Sat Nov 22 03:48:54 2008 Cross-referenced by PHPXref 0.7