public function loadImage() { $this->rejectIfKnownToHaveWrongOrientation(); parent::loadImage(); $this->recordMetadataIfNotDoneYet(); $imageResource = $this->imageResource; if ($this->desiredAspectRatio !== null) { $requiredOrientation = Image::getOrientationFromAspectRatio($this->desiredAspectRatio); // Only accept proper orientation pictures. if (!$this->hasOrientation($requiredOrientation)) { throw new \Exception('Incorrect orientation (should be ' . $requiredOrientation . ').', 1441638938); } if ($this->desiredAspectRatio !== $this->getAspectRatio()) { $imageResource = self::cropImageResourceToAspectRatio($imageResource, $this->desiredAspectRatio); } } if ($this->maxWidth !== null) { $imageWidth = \imagesx($imageResource); if ($imageWidth > $this->maxWidth) { $downsizedWidth = $this->maxWidth; $downsizedHeight = $downsizedWidth / $this->desiredAspectRatio; $imageResource = self::resizeImageResource($imageResource, $downsizedWidth, $downsizedHeight); } } $this->setImageResource($imageResource); $this->generateSignature(); $this->freeImageResourceMemory(); }