Beispiel #1
0
 public static function calculateSimilarity($pathToImage1, $pathToImage2)
 {
     if (!Image::isImageFile($pathToImage1)) {
         throw new \InvalidArgumentException(sprintf('Error: "%s" is not an image file.', $pathToImage1), 1449430004);
     }
     if (!Image::isImageFile($pathToImage2)) {
         throw new \InvalidArgumentException(sprintf('Error: "%s" is not an image file.', $pathToImage2), 1449430075);
     }
     $image1 = new ComparableImage($pathToImage1);
     $image2 = new Image($pathToImage2);
     return $image1->calculateSimilarityTo($image2);
 }
Beispiel #2
0
 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();
 }
Beispiel #3
0
 /**
  * Compare this image with the given image using signatures (i.e. downsized
  * copies of each image).
  * 
  * @param ComparableImage $otherImage The Image to compare this Image with.
  * @return int The difference between the two signatures.
  */
 public function compareWith($otherImage)
 {
     // Get this image's signature.
     $thisSignature = $this->getSignature();
     // Get the other image's signature.
     $otherSignature = $otherImage->getSignature();
     // Return the difference of the two signature images.
     return $thisSignature->getAbsoluteDifference($otherSignature);
 }