예제 #1
0
 public function testExifOrientation()
 {
     $images = array('1-top-left', '2-top-right', '3-bottom-right', '4-bottom-left', '5-left-top', '6-right-top', '7-right-bottom', '8-left-bottom');
     $resize = array('width' => 200, 'height' => 100);
     foreach ($images as $name) {
         $path = __DIR__ . '/tmp/' . $name . '.jpg';
         // Create test image
         $creator = new ThumbnailCreator();
         $creator->setSource(new File(__DIR__ . '/images/exif-orientation/' . $name . '.jpg'));
         $result = $creator->resize($resize);
         file_put_contents($path, $result);
         // Read test image
         $img = imagecreatefromjpeg($path);
         $width = imagesx($img);
         $height = imagesy($img);
         $rgb = imagecolorsforindex($img, imagecolorat($img, 0, 0));
         // Assert image size and red color (fuzzy) in the upper left corner
         $this->assertEquals($resize['width'], $width, 'Wrong width!');
         $this->assertEquals($resize['height'], $height, 'Wrong height!');
         $this->assertTrue($rgb['red'] > 250 && $rgb['green'] < 5 && $rgb['blue'] < 5, 'Wrong orientation!');
     }
 }
예제 #2
0
 public function testPortraitBorder()
 {
     $sample = __DIR__ . "/images/timthumbs/sample2.jpg";
     $creator = new ThumbnailCreator();
     $creator->setSource(new File($sample));
     $result = $creator->border(array('width' => 200, 'height' => 500));
     $compare = __DIR__ . "/images/timthumbs/border_sample2_200_500.jpg";
     file_put_contents(__DIR__ . "/tmp/test.jpg", $result);
     $this->assertEquals(getimagesize($compare), getimagesize(__DIR__ . "/tmp/test.jpg"));
     $this->assertEquals(filesize($compare), filesize(__DIR__ . "/tmp/test.jpg"));
 }