public function process()
{
$this->parseInput();
$this->basicCheck();
$this->purgeExif();
$inputImage = open_image($this->inputPath, $this->inputDim);
if ($inputImage === null) {
throw new ImageProcessorException(trans('users.show.edit.cover.upload.broken_file'));
}
if ($this->inputDim[0] === $this->targetDim[0] && $this->inputDim[1] === $this->targetDim[1]) {
if ($this->inputFileSize < $this->targetFileSize) {
return;
}
$image = $inputImage;
} else {
$start = [0, 0];
$inDim = [$this->inputDim[0], $this->inputDim[1]];
$outDim = [$this->targetDim[0], $this->targetDim[1]];
// figure out how to crop.
if ($this->inputDim[0] / $this->inputDim[1] >= $this->targetDim[0] / $this->targetDim[1]) {
$inDim[0] = $this->targetDim[0] / $this->targetDim[1] * $this->inputDim[1];
$start[0] = ($this->inputDim[0] - $inDim[0]) / 2;
} else {
$inDim[1] = $this->targetDim[1] / $this->targetDim[0] * $this->inputDim[0];
$start[1] = ($this->inputDim[1] - $inDim[1]) / 2;
}
// don't scale if input image is smaller.
if ($inDim[0] < $outDim[0] || $inDim[1] < $outDim[1]) {
$outDim = $inDim;
}
$image = imagecreatetruecolor($outDim[0], $outDim[1]);
imagecopyresampled($image, $inputImage, 0, 0, $start[0], $start[1], $outDim[0], $outDim[1], $inDim[0], $inDim[1]);
}
imagejpeg($image, $this->inputPath);
$this->parseInput(true);
}