Ejemplo n.º 1
0
 public function generate(FormatInterface $format)
 {
     // default output size egual input size
     if (empty($this->outputWidth)) {
         $this->setOutputWidth($this->inputWidth);
     }
     if (empty($this->outputHeight)) {
         $this->setOutputHeight($this->inputHeight);
     }
     // valid output size
     if (0 >= $this->outputWidth || 0 >= $this->outputHeight) {
         throw new \LengthException('Invalid image dimensions');
     }
     // create output image
     $this->output = imagecreatetruecolor($this->outputWidth, $this->outputHeight);
     // background color fill
     if (!is_null($this->colorFill)) {
         imagefill($this->output, 0, 0, $this->colorFill->getColor());
     }
     // copy input
     if ($this->input) {
         switch ($this->resizeMode) {
             case self::RESIZE_FIT:
                 $this->resize($this->output, $this->input, $this->outputWidth, $this->outputHeight, $this->inputWidth, $this->inputHeight);
                 break;
             case self::RESIZE_CROP:
                 $this->crop($this->output, $this->input, $this->outputWidth, $this->outputHeight, $this->inputWidth, $this->inputHeight);
                 break;
             default:
                 imagecopyresampled($this->output, $this->input, 0, 0, 0, 0, $this->outputWidth, $this->outputHeight, $this->inputWidth, $this->inputHeight);
         }
     }
     // apply filters
     foreach ($this->filters as $filter) {
         $filter->apply($this->output);
     }
     // generate output fill in the right format
     $format->generate($this->output, $this->outputPath);
 }
Ejemplo n.º 2
0
 /**
  * Generate image
  *
  * @param FormatInterface Image format.
  * @param string The path to save the file to.
  * @return void
  **/
 public function generate(FormatInterface $format, $filename = null)
 {
     if ($filename) {
         $this->isValidOutput($filename);
     }
     // create output image
     $output = imagecreatetruecolor($this->width, $this->height);
     // background color fill
     if (!is_null($this->colorFill)) {
         imagefill($output, 0, 0, $this->colorFill->getColor());
     }
     // copy image
     imagecopyresampled($output, $this->image, 0, 0, 0, 0, $this->width, $this->height, $this->width, $this->height);
     // apply transformations
     foreach ($this->transformations as $transformation) {
         $transformation->apply($output);
     }
     // apply filters
     foreach ($this->filters as $filter) {
         $filter->apply($output);
     }
     // generate output fill in the right format
     $format->generate($output, $filename);
 }