コード例 #1
0
ファイル: CropTest.php プロジェクト: raincreativelab/shackles
 public function testCroppingWithFullBoxDetails()
 {
     $chain = new Chain();
     $chain->setRules([new Duplicate(), new Crop(["width" => 500, "height" => 250, "crop-box-width" => 640, "x" => 0, "y" => 0])]);
     $this->_runner->writeAs("top-crop-{NAME}-{W}")->process("5639.jpg", 100)->run($chain);
     $this->assertTrue(file_exists($this->_runner->getImage()->getFullPath()));
     list($width, $height) = getimagesize($this->_runner->getImage()->getFullPath());
     $this->assertEquals(500, $width);
     $this->assertEquals(250, $height);
 }
コード例 #2
0
 public function testGrayscaleRule()
 {
     $chain = new Chain();
     $chain->setRules([new Duplicate(), new Grayscale()]);
     $basePath = __DIR__ . "/image";
     $runner = ChainBuilder::newRunner(["source" => $basePath, "format" => "gs-{NAME}"]);
     $runner->process("5639.jpg", 100)->run($chain);
     $file = glob($basePath . "/gs-5639*");
     $this->assertTrue(file_exists($file[0]));
 }
コード例 #3
0
 public function testDuplicateRule()
 {
     $chain = new Chain();
     $chain->setRules([new Duplicate()]);
     $basePath = __DIR__ . "/image";
     $runner = ChainBuilder::newRunner(["source" => $basePath]);
     $runner->process("5639.jpg")->run($chain);
     $file = $runner->getImage()->getFullPath();
     $this->assertTrue(file_exists($file));
     unlink($file);
 }
コード例 #4
0
 /**
  * Runs the chain and its all rules.
  * You can assign multiple chains to process one image
  *
  * run(chain1, chain2, ...)
  *
  * @param Chain $chain Chain object
  *
  * @return void
  */
 public function run(Chain $chain)
 {
     $this->_throwExceptionIfBaseDirectoryIsNotSet();
     $this->_throwExceptionIfNoImageIsFound();
     $chains = func_get_args();
     /** @var Chain $chain */
     foreach ($chains as $chain) {
         // Inject the file system to the rules
         $rules = $chain->getRules();
         /** @var Rule $rule */
         foreach ($rules as $rule) {
             $rule->setFileSystem($this->_fileSystem);
         }
         $chain->process($this->_image);
         $this->_formatFile($this->_image);
     }
 }