Beispiel #1
0
 /**
  * 
  * @param string $filename
  * @param image $sourceImage
  * @param rectangle $rectangle
  */
 public function __construct($filename, $sourceImage, $rectangle)
 {
     parent::__construct($filename);
     $this->setType($sourceImage->getType());
     $this->fromArea($sourceImage, $rectangle);
     $this->save();
 }
Beispiel #2
0
 /**
  *
  * @param image $image
  */
 public function save($image)
 {
     if (is_resource($image->meta)) {
         switch ($image->getType()) {
             case 1:
                 imagegif($image->meta, $image->getFilename());
                 break;
             case 2:
                 imagejpeg($image->meta, $image->getFilename(), self::$_jpegQuality);
                 break;
             case 3:
                 imagepng($image->meta, $image->getFilename(), self::$_pngCompression, self::$_pngFilters);
                 break;
             default:
                 break;
         }
     }
 }
$dir = dirname(__FILE__);
$fixtures = $dir . '/../fixtures/image';
require $dir . '/../../lib/php/model/image.class.php';
$baseImage = $fixtures . '/FordMustang.jpg';
$waterMark = $fixtures . '/black-opacity.png';
$image = new image($baseImage);
$images = array();
logSection($image->isActive(), 'is valid image', 'info');
if (!$image->isActive()) {
    logSection('exit', 'image is invalid, operation can not be finished', 'error');
}
$width = $image->getData('width');
$height = $image->getData('height');
logSection($width . 'x' . $height, 'test getData method', 'info');
logSection('jpeg' == $image->getType(), 'test getType method', 'info');
$image->resize(500, 500, 'height');
$image->save($fixtures . '/FordMustang-500h.jpg');
$images[] = $fixtures . '/FordMustang-500h.jpg';
logSection(file_exists($fixtures . '/FordMustang-500h.jpg'), '->resize(500, 500, height)->save(FordMustang-500h.jpg)');
logSection($image->getData('height') == 500, 'height == 500');
$image->resize(500, 500, 'width');
$image->save($fixtures . '/FordMustang-500w.jpg');
$images[] = $fixtures . '/FordMustang-500w.jpg';
logSection(file_exists($fixtures . '/FordMustang-500w.jpg'), '->resize(500, 500, width)->save(FordMustang-500w.jpg)');
logSection($image->getData('width') == 500, 'width == 500');
$image->resize(500, 500, 'auto');
$image->save($fixtures . '/FordMustang-500a.jpg');
$images[] = $fixtures . '/FordMustang-500a.jpg';
logSection(file_exists($fixtures . '/FordMustang-500w.jpg'), '->resize(500, 500, auto)->save(FordMustang-500a.jpg)');
logSection($image->getData('width') == 500, 'width == 500');