/** * Resize an image using the computed settings. * * @param FileInterface $file * @param Style $style * @return string */ public function resize(FileInterface $file, Style $style) { $filePath = tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getFilename(); list($width, $height, $option) = $this->parseStyleDimensions($style); $method = "resize" . ucfirst($option); if ($method == 'resizeCustom') { $this->resizeCustom($file, $style->dimensions)->save($filePath, $style->convertOptions); return $filePath; } $image = $this->imagine->open($file->getRealPath()); if ($style->autoOrient) { $image = $this->autoOrient($file->getRealPath(), $image); } $this->{$method}($image, $width, $height)->save($filePath, $style->convertOptions); return $filePath; }
/** * Process the queuedForWrite que. */ protected function flushWrites() { foreach ($this->queuedForWrite as $style) { if ($style->dimensions && $this->uploadedFile->isImage()) { $file = $this->resizer->resize($this->uploadedFile, $style); } else { $file = $this->uploadedFile->getRealPath(); } $filePath = $this->path($style->name); $this->move($file, $filePath); } $this->queuedForWrite = []; }