Skip to content

Commit

Permalink
With the last commit it was 11% slower. Now only create another tempo…
Browse files Browse the repository at this point in the history
…rary file if really there are faces to encode
  • Loading branch information
matiasdelellis committed Jul 23, 2020
1 parent 8c76771 commit f91d8cb
Showing 1 changed file with 32 additions and 12 deletions.
44 changes: 32 additions & 12 deletions lib/Helper/TempImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class TempImage extends Image {
/** @var string */
private $imagePath;

/** @var string */
/** @var string|null */
private $orientedImagePath;

/** @var string */
/** @var string|null */
private $resizedImagePath;

/** @var string */
Expand Down Expand Up @@ -84,11 +84,13 @@ public function getImagePath(): string {
}

/**
* Get the path of orig image
* Get the path of oriented or original image
*
* @return string
*/
public function getOrientedImagePath(): string {
$this->prepareOrientedImage();

return $this->orientedImagePath;
}

Expand Down Expand Up @@ -142,17 +144,10 @@ private function prepareImage() {
return;
}

if ($this->getOrientation() > 1) {
$this->fixOrientation();
$this->orientedImagePath = $this->tempManager->getTemporaryFile();
$this->save($this->orientedImagePath, $this->preferredMimeType);
} else {
$this->orientedImagePath = $this->imagePath;
}

$this->fixOrientation();
$this->ratio = $this->resizeImage();
$this->resizedImagePath = $this->tempManager->getTemporaryFile();

$this->resizedImagePath = $this->tempManager->getTemporaryFile();
$this->save($this->resizedImagePath, $this->preferredMimeType);
}

Expand Down Expand Up @@ -184,4 +179,29 @@ private function resizeImage(): float {
return 1 / $scaleFactor;
}

/**
* Obtain a temporary image according to the imposed restrictions.
*
*/
private function prepareOrientedImage() {
if (!is_null($this->orientedImagePath)) {
return;
}

$this->loadFromFile($this->imagePath);

if (!$this->valid()) {
throw new \RuntimeException("Image is not valid, probably cannot be loaded");
}

if ($this->getOrientation() > 1) {
$this->fixOrientation();

$this->orientedImagePath = $this->tempManager->getTemporaryFile();
$this->save($this->orientedImagePath, $this->preferredMimeType);
} else {
$this->orientedImagePath = $this->imagePath;
}
}

}

0 comments on commit f91d8cb

Please sign in to comment.