├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.MD ├── composer.json ├── phpunit.xml ├── phpunit.xml.dist ├── src ├── Annotation │ ├── Block.php │ ├── BoundingPoly.php │ ├── Color.php │ ├── CropHint.php │ ├── CropHintsAnnotation.php │ ├── CropHintsParams.php │ ├── DetectedBreak.php │ ├── DetectedLanguage.php │ ├── DominantColor.php │ ├── EntityAnnotation.php │ ├── Error.php │ ├── FaceAnnotation.php │ ├── ImageContext.php │ ├── ImagePropertiesAnnotation.php │ ├── Landmark.php │ ├── LatLng.php │ ├── LatLongRect.php │ ├── Likelihood.php │ ├── Location.php │ ├── Page.php │ ├── Paragraph.php │ ├── Position.php │ ├── Property.php │ ├── SafeSearchAnnotation.php │ ├── Symbol.php │ ├── TextAnnotation.php │ ├── TextProperty.php │ ├── Type.php │ ├── Vertex.php │ ├── WebDetection.php │ ├── WebDetectionParams.php │ ├── WebEntity.php │ ├── WebImage.php │ ├── WebPage.php │ └── Word.php ├── Exception │ ├── ImageException.php │ └── UnknownFeatureException.php ├── Feature.php ├── Hydrator │ ├── AnnotateImageHydrator.php │ ├── AnnotationHydrator.php │ ├── Strategy │ │ ├── BlocksStrategy.php │ │ ├── BoundingPolyStrategy.php │ │ ├── CropHintStrategy.php │ │ ├── CropHintsParamsStrategy.php │ │ ├── DetectedBreakStrategy.php │ │ ├── DetectedLanguagesStrategy.php │ │ ├── DominantColorsStrategy.php │ │ ├── LandmarkStrategy.php │ │ ├── LatLongRectStrategy.php │ │ ├── LocationStrategy.php │ │ ├── PagesStrategy.php │ │ ├── ParagraphsStrategy.php │ │ ├── PropertyStrategy.php │ │ ├── SymbolsStrategy.php │ │ ├── TextPropertyStrategy.php │ │ ├── WebDetectionParamsStrategy.php │ │ ├── WebEntitiesStrategy.php │ │ ├── WebImagesStrategy.php │ │ ├── WebPagesStrategy.php │ │ └── WordsStrategy.php │ ├── SubAnnotationHydrator.php │ ├── TextAnnotationHydrator.php │ └── WebDetectionHydrator.php ├── Image.php ├── Request │ ├── Image │ │ ├── AbstractImage.php │ │ ├── Base64Image.php │ │ ├── BinaryImage.php │ │ ├── GoogleCloudImage.php │ │ ├── ImageInterface.php │ │ ├── LocalImage.php │ │ └── RemoteImage.php │ └── VisionRequest.php ├── Response │ └── AnnotateImageResponse.php └── Vision.php └── tests ├── FeatureTest.php ├── Hydrator ├── AnnotateImageHydratorTest.php └── Strategy │ ├── BoundingPolyStrategyTest.php │ ├── CropHintStrategyTest.php │ ├── CropHintsParamsStrategyTest.php │ ├── DetectedBreakStrategyTest.php │ ├── DetectedLanguagesStrategyTest.php │ ├── DominantColorsStrategyTest.php │ ├── LandmarkStrategyTest.php │ ├── LatLongRectStrategyTest.php │ ├── LocationStrategyTest.php │ ├── PropertyStrategyTest.php │ ├── WebDetectionParamsStrategyTest.php │ ├── WebEntitiesStrategyTest.php │ ├── WebImagesStrategyTest.php │ └── WebPagesStrategyTest.php ├── ImageTest.php ├── Request ├── Image │ ├── Base64ImageTest.php │ ├── BinaryImageTest.php │ ├── GoogleCloudImageTest.php │ ├── LocalImageTest.php │ └── RemoteImageTest.php └── VisionRequestTest.php ├── Resources └── testimage.jpg └── bootstrap.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | phpunit.xml 3 | composer.lock 4 | /example 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | php: 3 | - '5.6' 4 | - '7.0' 5 | - '7.1' 6 | - '7.2' 7 | install: 8 | - composer install 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at jordi@jordikroon.nl. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Contributions are **welcome** and will be fully **credited**. 4 | 5 | We accept contributions via Pull Requests on [Github](https://github.com/jordikroon/Php-Google-Vision-Api). 6 | 7 | 8 | ## Pull Requests 9 | 10 | - **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer). 11 | 12 | - **Add tests!** - Your patch won't be accepted if it doesn't have tests. 13 | 14 | - **Document any change in behaviour** - Make sure the README and any other relevant documentation are kept up-to-date. 15 | 16 | - **Consider our release cycle** - We try to follow SemVer. Randomly breaking public APIs is not an option. 17 | 18 | - **Create topic branches** - Don't ask us to pull from your master branch. 19 | 20 | - **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. 21 | 22 | - **Ensure tests pass!** - Please run the tests (see below) before submitting your pull request, and make sure they pass. We won't accept a patch until all tests pass. 23 | 24 | ## Running Tests 25 | 26 | ``` bash 27 | $ ./vendor/bin/phpunit 28 | ``` 29 | 30 | **Thank you for making this project better**! 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jordi Kroon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | Google Vision, PHP Client 2 | ========================= 3 | 4 | [![Latest Stable Version](https://poser.pugx.org/jordikroon/google-vision/v/stable)](https://packagist.org/packages/jordikroon/google-vision) 5 | [![Build Status](https://travis-ci.org/jordikroon/Php-Google-Vision-Api.svg?branch=master)](https://travis-ci.org/jordikroon/Php-Google-Vision-Api) 6 | [![Dependency Status](https://www.versioneye.com/user/projects/588bdad0c64626002e5d6baf/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/588bdad0c64626002e5d6baf) 7 | [![License](https://poser.pugx.org/jordikroon/google-vision/license)](https://packagist.org/packages/jordikroon/google-vision) 8 | 9 | ## Instalation 10 | 11 | The easiest way to install Google Vision is through [Composer](http://getcomposer.org). 12 | 13 | ```bash 14 | composer require jordikroon/google-vision 15 | ``` 16 | 17 | Next is to obtain an API key through the [Google Cloud Platform](https://cloud.google.com). To get one visit the link below. 18 | https://cloud.google.com/vision/docs/quickstart 19 | 20 | Requirements 21 | ------------ 22 | - [PHP >= 5.6](http://php.net/releases/5_6_0.php) 23 | - [Curl extension](http://php.net/manual/en/curl.installation.php) 24 | 25 | Basic usage 26 | ----------- 27 | 28 | ```php 29 | $vision = new \Vision\Vision( 30 | $apiKey, 31 | [ 32 | // See a list of all features in the table below 33 | // Feature, Limit 34 | new \Vision\Feature(\Vision\Feature::FACE_DETECTION, 100), 35 | ] 36 | ); 37 | 38 | $imagePath = $_FILES['file']['tmp_name']; 39 | $response = $vision->request( 40 | // See a list of all image loaders in the table below 41 | new \Vision\Request\Image\LocalImage($imagePath) 42 | ); 43 | 44 | $faces = $response->getFaceAnnotations(); 45 | foreach ($faces as $face) { 46 | foreach ($face->getBoundingPoly()->getVertices() as $vertex) { 47 | echo sprintf('Person at position X %f and Y %f', $vertex->getX(), $vertex->getY()); 48 | } 49 | } 50 | ``` 51 | 52 | Available features 53 | ------------------ 54 | 55 | | Name | Constant | 56 | | :-----------------------------------------------------------------------------------| :---------------------------------------- | 57 | | [LABEL_DETECTION](https://cloud.google.com/vision/docs/detecting-labels) | \Vision\Feature::LABEL_DETECTION         | 58 | | [TEXT_DETECTION](https://cloud.google.com/vision/docs/detecting-text) | \Vision\Feature::TEXT_DETECTION | 59 | | [FACE_DETECTION](https://cloud.google.com/vision/docs/detecting-faces) | \Vision\Feature::FACE_DETECTION | 60 | | [LANDMARK_DETECTION](https://cloud.google.com/vision/docs/detecting-landmarks) | \Vision\Feature::LANDMARK_DETECTION | 61 | | [LOGO_DETECTION](https://cloud.google.com/vision/docs/detecting-logos) | \Vision\Feature::LOGO_DETECTION | 62 | | [SAFE_SEARCH_DETECTION](https://cloud.google.com/vision/docs/detecting-safe-search) | \Vision\Feature::SAFE_SEARCH_DETECTION | 63 | | [IMAGE_PROPERTIES](https://cloud.google.com/vision/docs/detecting-properties) | \Vision\Feature::IMAGE_PROPERTIES | 64 | | [WEB_DETECTION](https://cloud.google.com/vision/docs/detecting-web) | \Vision\Feature::WEB_DETECTION | 65 | | [CROP_HINTS](https://cloud.google.com/vision/docs/detecting-crop-hints) | \Vision\Feature::CROP_HINTS | 66 | | [DOCUMENT_TEXT_DETECTION](https://cloud.google.com/vision/docs/detecting-fulltext) | \Vision\Feature::DOCUMENT_TEXT_DETECTION | 67 | 68 | Available image loaders 69 | ------------------ 70 | 71 | | Image loader | Description | 72 | | :--------------------------------------------------------------------------------| :------------------------------------------------------- | 73 | | [\Vision\Request\Image\Base64Image](src/Request/Image/Base64Image.php) | Loads Base64 encoded images         | 74 | | [\Vision\Request\Image\BinaryImage](src/Request/Image/BinaryImage.php) | Loads binary images (file_get_contents or fopen) | 75 | | [\Vision\Request\Image\GoogleCloudImage](src/Request/Image/GoogleCloudImage.php) | Loads images from a Google Cloud bucket | 76 | | [\Vision\Request\Image\LocalImage](src/Request/Image/LocalImage.php) | Loads a locally stored image | 77 | | [\Vision\Request\Image\RemoteImage](src/Request/Image/RemoteImage.php) | Loads a remote (HTTP/HTTPS) image somewhere from the web | 78 | 79 | To add a feature, add a `new \Vision\Feature` instance to features array used as second parameter. See [Basic Usage](#Basic-Usage) for a full example. 80 | ```php 81 | new \Vision\Feature($feature, $maxResults); 82 | ``` 83 | 84 | Run tests 85 | --------- 86 | 87 | ```bash 88 | $ composer install 89 | $ ./vendor/bin/phpunit 90 | ``` 91 | 92 | Authors 93 | ------- 94 | Jordi Kroon | [Github](https://github.com/jordikroon) | [Twitter](https://twitter.com/jordi12100) | [jordikroon.nl](https://jordikroon.nl) 95 | 96 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jordikroon/google-vision", 3 | "description": "Google Vision Api for PHP (https://cloud.google.com/vision/)", 4 | "keywords": ["Google","Cloud", "Vision", "Api", "Image", "Face", "Recognition", "Landmark"], 5 | "license": "MIT", 6 | "type": "library", 7 | "authors": [ 8 | { 9 | "name": "Jordi Kroon", 10 | "email": "jordi@jordikroon.nl" 11 | } 12 | ], 13 | "require": { 14 | "php": "^5.6 || ^7.0", 15 | "guzzlehttp/guzzle": "^6.2.2", 16 | "zendframework/zend-hydrator": "^2.2" 17 | }, 18 | "require-dev": { 19 | "phpunit/phpunit": "^5.7" 20 | }, 21 | "autoload": { 22 | "psr-4": { 23 | "Vision\\": "src" 24 | } 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "Vision\\Tests\\": "tests/" 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | 9 | 10 | src 11 | 12 | src/ 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | tests 6 | 7 | 8 | 9 | 10 | src 11 | 12 | src/ 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/Annotation/Block.php: -------------------------------------------------------------------------------- 1 | property = $property; 47 | $this->boundingBox = $boundingBox; 48 | $this->paragraphs = $paragraphs; 49 | $this->blockType = $blockType; 50 | } 51 | 52 | /** 53 | * @return TextProperty 54 | */ 55 | public function getProperty() 56 | { 57 | return $this->property; 58 | } 59 | 60 | /** 61 | * @param TextProperty $property 62 | */ 63 | public function setProperty($property) 64 | { 65 | $this->property = $property; 66 | } 67 | 68 | /** 69 | * @return BoundingPoly 70 | */ 71 | public function getBoundingBox() 72 | { 73 | return $this->boundingBox; 74 | } 75 | 76 | /** 77 | * @param BoundingPoly $boundingBox 78 | */ 79 | public function setBoundingBox($boundingBox) 80 | { 81 | $this->boundingBox = $boundingBox; 82 | } 83 | 84 | /** 85 | * @return Paragraph[] 86 | */ 87 | public function getParagraphs() 88 | { 89 | return $this->paragraphs; 90 | } 91 | 92 | /** 93 | * @param Paragraph[] $paragraphs 94 | */ 95 | public function setParagraphs($paragraphs) 96 | { 97 | $this->paragraphs = $paragraphs; 98 | } 99 | 100 | /** 101 | * @return string 102 | */ 103 | public function getBlockType() 104 | { 105 | return $this->blockType; 106 | } 107 | 108 | /** 109 | * @param string $blockType 110 | */ 111 | public function setBlockType($blockType) 112 | { 113 | $this->blockType = $blockType; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/Annotation/BoundingPoly.php: -------------------------------------------------------------------------------- 1 | vertices; 18 | } 19 | 20 | /** 21 | * @param Vertex $vertex 22 | */ 23 | public function addVertex($vertex) 24 | { 25 | $this->vertices[] = $vertex; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Annotation/Color.php: -------------------------------------------------------------------------------- 1 | red = $red; 30 | $this->green = $green; 31 | $this->blue = $blue; 32 | } 33 | 34 | /** 35 | * @return float 36 | */ 37 | public function getRed() 38 | { 39 | return $this->red; 40 | } 41 | 42 | /** 43 | * @param float $red 44 | */ 45 | public function setRed($red) 46 | { 47 | $this->red = $red; 48 | } 49 | 50 | /** 51 | * @return float 52 | */ 53 | public function getGreen() 54 | { 55 | return $this->green; 56 | } 57 | 58 | /** 59 | * @param float $green 60 | */ 61 | public function setGreen($green) 62 | { 63 | $this->green = $green; 64 | } 65 | 66 | /** 67 | * @return float 68 | */ 69 | public function getBlue() 70 | { 71 | return $this->blue; 72 | } 73 | 74 | /** 75 | * @param float $blue 76 | */ 77 | public function setBlue($blue) 78 | { 79 | $this->blue = $blue; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/CropHint.php: -------------------------------------------------------------------------------- 1 | boundingPoly = $boundingPoly; 30 | $this->confidence = $confidence; 31 | $this->importanceFraction = $importanceFraction; 32 | } 33 | 34 | /** 35 | * @return BoundingPoly 36 | */ 37 | public function getBoundingPoly() 38 | { 39 | return $this->boundingPoly; 40 | } 41 | 42 | /** 43 | * @param BoundingPoly $boundingPoly 44 | */ 45 | public function setBoundingPoly($boundingPoly) 46 | { 47 | $this->boundingPoly = $boundingPoly; 48 | } 49 | 50 | /** 51 | * @return int 52 | */ 53 | public function getConfidence() 54 | { 55 | return $this->confidence; 56 | } 57 | 58 | /** 59 | * @param int $confidence 60 | */ 61 | public function setConfidence($confidence) 62 | { 63 | $this->confidence = $confidence; 64 | } 65 | 66 | /** 67 | * @return int 68 | */ 69 | public function getImportanceFraction() 70 | { 71 | return $this->importanceFraction; 72 | } 73 | 74 | /** 75 | * @param int $importanceFraction 76 | */ 77 | public function setImportanceFraction($importanceFraction) 78 | { 79 | $this->importanceFraction = $importanceFraction; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/CropHintsAnnotation.php: -------------------------------------------------------------------------------- 1 | cropHints; 18 | } 19 | 20 | /** 21 | * @param CropHint[] $cropHints 22 | */ 23 | public function setCropHints($cropHints) 24 | { 25 | $this->cropHints = $cropHints; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Annotation/CropHintsParams.php: -------------------------------------------------------------------------------- 1 | aspectRatios = $aspectRatios; 18 | } 19 | 20 | /** 21 | * @return array 22 | */ 23 | public function getAspectRatios() 24 | { 25 | return $this->aspectRatios; 26 | } 27 | 28 | /** 29 | * @param array $aspectRatios 30 | */ 31 | public function setAspectRatios($aspectRatios) 32 | { 33 | $this->aspectRatios = $aspectRatios; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Annotation/DetectedBreak.php: -------------------------------------------------------------------------------- 1 | type = $type; 31 | $this->isPrefix = $isPrefix; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getType() 38 | { 39 | return $this->type; 40 | } 41 | 42 | /** 43 | * @param string $type 44 | */ 45 | public function setType($type) 46 | { 47 | $this->type = $type; 48 | } 49 | 50 | /** 51 | * @return bool 52 | */ 53 | public function isPrefix() 54 | { 55 | return $this->isPrefix; 56 | } 57 | 58 | /** 59 | * @param bool $isPrefix 60 | */ 61 | public function setIsPrefix($isPrefix) 62 | { 63 | $this->isPrefix = $isPrefix; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/Annotation/DetectedLanguage.php: -------------------------------------------------------------------------------- 1 | languageCode = $languageCode; 24 | $this->confidence = $confidence; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getLanguageCode() 31 | { 32 | return $this->languageCode; 33 | } 34 | 35 | /** 36 | * @param string $languageCode 37 | */ 38 | public function setLanguageCode($languageCode) 39 | { 40 | $this->languageCode = $languageCode; 41 | } 42 | 43 | /** 44 | * @return float|null 45 | */ 46 | public function getConfidence() 47 | { 48 | return $this->confidence; 49 | } 50 | 51 | /** 52 | * @param float|null $confidence 53 | */ 54 | public function setConfidence($confidence) 55 | { 56 | $this->confidence = $confidence; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/DominantColor.php: -------------------------------------------------------------------------------- 1 | color; 28 | } 29 | 30 | /** 31 | * @param Color $color 32 | */ 33 | public function setColor($color) 34 | { 35 | $this->color = $color; 36 | } 37 | 38 | /** 39 | * @return float 40 | */ 41 | public function getScore() 42 | { 43 | return $this->score; 44 | } 45 | 46 | /** 47 | * @param float $score 48 | */ 49 | public function setScore($score) 50 | { 51 | $this->score = $score; 52 | } 53 | 54 | /** 55 | * @return float 56 | */ 57 | public function getPixelFraction() 58 | { 59 | return $this->pixelFraction; 60 | } 61 | 62 | /** 63 | * @param float $pixelFraction 64 | */ 65 | public function setPixelFraction($pixelFraction) 66 | { 67 | $this->pixelFraction = $pixelFraction; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Annotation/EntityAnnotation.php: -------------------------------------------------------------------------------- 1 | mid; 43 | } 44 | 45 | /** 46 | * @param string $mid 47 | */ 48 | public function setMid($mid) 49 | { 50 | $this->mid = $mid; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getDescription() 57 | { 58 | return $this->description; 59 | } 60 | 61 | /** 62 | * @param string $description 63 | */ 64 | public function setDescription($description) 65 | { 66 | $this->description = $description; 67 | } 68 | 69 | /** 70 | * @return float 71 | */ 72 | public function getScore() 73 | { 74 | return $this->score; 75 | } 76 | 77 | /** 78 | * @param float $score 79 | */ 80 | public function setScore($score) 81 | { 82 | $this->score = $score; 83 | } 84 | 85 | /** 86 | * @return BoundingPoly 87 | */ 88 | public function getBoundingPoly() 89 | { 90 | return $this->boundingPoly; 91 | } 92 | 93 | /** 94 | * @param BoundingPoly $boundingPoly 95 | */ 96 | public function setBoundingPoly($boundingPoly) 97 | { 98 | $this->boundingPoly = $boundingPoly; 99 | } 100 | 101 | /** 102 | * @return Location[] 103 | */ 104 | public function getLocations() 105 | { 106 | return $this->locations; 107 | } 108 | 109 | /** 110 | * @param Location[] $locations 111 | */ 112 | public function setLocations($locations) 113 | { 114 | $this->locations = $locations; 115 | } 116 | 117 | /** 118 | * @return Property[] 119 | */ 120 | public function getProperties() 121 | { 122 | return $this->properties; 123 | } 124 | 125 | /** 126 | * @param Property[] $properties 127 | */ 128 | public function setProperties($properties) 129 | { 130 | $this->properties = $properties; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/Annotation/Error.php: -------------------------------------------------------------------------------- 1 | code; 35 | } 36 | 37 | /** 38 | * @param int $code 39 | */ 40 | public function setCode($code) 41 | { 42 | $this->code = $code; 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getMessage() 49 | { 50 | return $this->message; 51 | } 52 | 53 | /** 54 | * @param string $message 55 | */ 56 | public function setMessage($message) 57 | { 58 | $this->message = $message; 59 | } 60 | 61 | /** 62 | * @return string 63 | */ 64 | public function getStatus() 65 | { 66 | return $this->status; 67 | } 68 | 69 | /** 70 | * @param string $status 71 | */ 72 | public function setStatus($status) 73 | { 74 | $this->status = $status; 75 | } 76 | 77 | /** 78 | * @return array 79 | */ 80 | public function getDetails() 81 | { 82 | return $this->details; 83 | } 84 | 85 | /** 86 | * @param array $details 87 | */ 88 | public function setDetails($details) 89 | { 90 | $this->details = $details; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /src/Annotation/FaceAnnotation.php: -------------------------------------------------------------------------------- 1 | boundingPoly; 95 | } 96 | 97 | /** 98 | * @param BoundingPoly $boundingPoly 99 | */ 100 | public function setBoundingPoly($boundingPoly) 101 | { 102 | $this->boundingPoly = $boundingPoly; 103 | } 104 | 105 | /** 106 | * @return BoundingPoly 107 | */ 108 | public function getFdBoundingPoly() 109 | { 110 | return $this->fdBoundingPoly; 111 | } 112 | 113 | /** 114 | * @param BoundingPoly $fdBoundingPoly 115 | */ 116 | public function setFdBoundingPoly($fdBoundingPoly) 117 | { 118 | $this->fdBoundingPoly = $fdBoundingPoly; 119 | } 120 | 121 | /** 122 | * @return Landmark[] 123 | */ 124 | public function getLandmarks() 125 | { 126 | return $this->landmarks; 127 | } 128 | 129 | /** 130 | * @param Landmark[] $landmarks 131 | */ 132 | public function setLandmarks($landmarks) 133 | { 134 | $this->landmarks = $landmarks; 135 | } 136 | 137 | /** 138 | * @return float 139 | */ 140 | public function getRollAngle() 141 | { 142 | return $this->rollAngle; 143 | } 144 | 145 | /** 146 | * @param float $rollAngle 147 | */ 148 | public function setRollAngle($rollAngle) 149 | { 150 | $this->rollAngle = $rollAngle; 151 | } 152 | 153 | /** 154 | * @return float 155 | */ 156 | public function getPanAngle() 157 | { 158 | return $this->panAngle; 159 | } 160 | 161 | /** 162 | * @param float $panAngle 163 | */ 164 | public function setPanAngle($panAngle) 165 | { 166 | $this->panAngle = $panAngle; 167 | } 168 | 169 | /** 170 | * @return float 171 | */ 172 | public function getTiltAngle() 173 | { 174 | return $this->tiltAngle; 175 | } 176 | 177 | /** 178 | * @param float $tiltAngle 179 | */ 180 | public function setTiltAngle($tiltAngle) 181 | { 182 | $this->tiltAngle = $tiltAngle; 183 | } 184 | 185 | /** 186 | * @return float 187 | */ 188 | public function getDetectionConfidence() 189 | { 190 | return $this->detectionConfidence; 191 | } 192 | 193 | /** 194 | * @param float $detectionConfidence 195 | */ 196 | public function setDetectionConfidence($detectionConfidence) 197 | { 198 | $this->detectionConfidence = $detectionConfidence; 199 | } 200 | 201 | /** 202 | * @return float 203 | */ 204 | public function getLandmarkingConfidence() 205 | { 206 | return $this->landmarkingConfidence; 207 | } 208 | 209 | /** 210 | * @param float $landmarkingConfidence 211 | */ 212 | public function setLandmarkingConfidence($landmarkingConfidence) 213 | { 214 | $this->landmarkingConfidence = $landmarkingConfidence; 215 | } 216 | 217 | /** 218 | * @return string 219 | */ 220 | public function getJoyLikelihood() 221 | { 222 | return $this->joyLikelihood; 223 | } 224 | 225 | /** 226 | * @param string $joyLikelihood 227 | */ 228 | public function setJoyLikelihood($joyLikelihood) 229 | { 230 | $this->joyLikelihood = $joyLikelihood; 231 | } 232 | 233 | /** 234 | * @return string 235 | */ 236 | public function getSorrowLikelihood() 237 | { 238 | return $this->sorrowLikelihood; 239 | } 240 | 241 | /** 242 | * @param string $sorrowLikelihood 243 | */ 244 | public function setSorrowLikelihood($sorrowLikelihood) 245 | { 246 | $this->sorrowLikelihood = $sorrowLikelihood; 247 | } 248 | 249 | /** 250 | * @return string 251 | */ 252 | public function getAngerLikelihood() 253 | { 254 | return $this->angerLikelihood; 255 | } 256 | 257 | /** 258 | * @param string $angerLikelihood 259 | */ 260 | public function setAngerLikelihood($angerLikelihood) 261 | { 262 | $this->angerLikelihood = $angerLikelihood; 263 | } 264 | 265 | /** 266 | * @return string 267 | */ 268 | public function getSurpriseLikelihood() 269 | { 270 | return $this->surpriseLikelihood; 271 | } 272 | 273 | /** 274 | * @param string $surpriseLikelihood 275 | */ 276 | public function setSurpriseLikelihood($surpriseLikelihood) 277 | { 278 | $this->surpriseLikelihood = $surpriseLikelihood; 279 | } 280 | 281 | /** 282 | * @return string 283 | */ 284 | public function getUnderExposedLikelihood() 285 | { 286 | return $this->underExposedLikelihood; 287 | } 288 | 289 | /** 290 | * @param string $underExposedLikelihood 291 | */ 292 | public function setUnderExposedLikelihood($underExposedLikelihood) 293 | { 294 | $this->underExposedLikelihood = $underExposedLikelihood; 295 | } 296 | 297 | /** 298 | * @return string 299 | */ 300 | public function getBlurredLikelihood() 301 | { 302 | return $this->blurredLikelihood; 303 | } 304 | 305 | /** 306 | * @param string $blurredLikelihood 307 | */ 308 | public function setBlurredLikelihood($blurredLikelihood) 309 | { 310 | $this->blurredLikelihood = $blurredLikelihood; 311 | } 312 | 313 | /** 314 | * @return string 315 | */ 316 | public function getHeadwearLikelihood() 317 | { 318 | return $this->headwearLikelihood; 319 | } 320 | 321 | /** 322 | * @param string $headwearLikelihood 323 | */ 324 | public function setHeadwearLikelihood($headwearLikelihood) 325 | { 326 | $this->headwearLikelihood = $headwearLikelihood; 327 | } 328 | } 329 | -------------------------------------------------------------------------------- /src/Annotation/ImageContext.php: -------------------------------------------------------------------------------- 1 | latLongRect; 33 | } 34 | 35 | /** 36 | * @param LatLongRect $latLongRect 37 | */ 38 | public function setLatLongRect($latLongRect) 39 | { 40 | $this->latLongRect = $latLongRect; 41 | } 42 | 43 | /** 44 | * @return array 45 | */ 46 | public function getLanguageHints() 47 | { 48 | return $this->languageHints; 49 | } 50 | 51 | /** 52 | * @param array $languageHints 53 | */ 54 | public function setLanguageHints($languageHints) 55 | { 56 | $this->languageHints = $languageHints; 57 | } 58 | 59 | /** 60 | * @param string $language 61 | * @param string $hint 62 | */ 63 | public function addLanguageHint($language, $hint) 64 | { 65 | $this->languageHints[$language] = $hint; 66 | } 67 | 68 | /** 69 | * @return CropHintsParams 70 | */ 71 | public function getCropHintsParams() 72 | { 73 | return $this->cropHintsParams; 74 | } 75 | 76 | /** 77 | * @param CropHintsParams $cropHintsParams 78 | */ 79 | public function setCropHintsParams($cropHintsParams) 80 | { 81 | $this->cropHintsParams = $cropHintsParams; 82 | } 83 | 84 | /** 85 | * @return WebDetectionParams 86 | */ 87 | public function getWebDetectionParams() 88 | { 89 | return $this->webDetectionParams; 90 | } 91 | 92 | /** 93 | * @param WebDetectionParams $webDetectionParams 94 | */ 95 | public function setWebDetectionParams($webDetectionParams) 96 | { 97 | $this->webDetectionParams = $webDetectionParams; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/Annotation/ImagePropertiesAnnotation.php: -------------------------------------------------------------------------------- 1 | dominantColors; 18 | } 19 | 20 | /** 21 | * @param DominantColor[] $dominantColors 22 | */ 23 | public function setDominantColors($dominantColors) 24 | { 25 | $this->dominantColors = $dominantColors; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Annotation/Landmark.php: -------------------------------------------------------------------------------- 1 | type; 24 | } 25 | 26 | /** 27 | * @param string $type 28 | */ 29 | public function setType($type) 30 | { 31 | $this->type = $type; 32 | } 33 | 34 | /** 35 | * @return Position 36 | */ 37 | public function getPosition() 38 | { 39 | return $this->position; 40 | } 41 | 42 | /** 43 | * @param Position $position 44 | */ 45 | public function setPosition($position) 46 | { 47 | $this->position = $position; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/Annotation/LatLng.php: -------------------------------------------------------------------------------- 1 | latitude = $latitude; 24 | $this->longitude = $longitude; 25 | } 26 | 27 | /** 28 | * @return float 29 | */ 30 | public function getLatitude() 31 | { 32 | return $this->latitude; 33 | } 34 | 35 | /** 36 | * @param float $latitude 37 | */ 38 | public function setLatitude($latitude) 39 | { 40 | $this->latitude = $latitude; 41 | } 42 | 43 | /** 44 | * @return float 45 | */ 46 | public function getLongitude() 47 | { 48 | return $this->longitude; 49 | } 50 | 51 | /** 52 | * @param float $longitude 53 | */ 54 | public function setLongitude($longitude) 55 | { 56 | $this->longitude = $longitude; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/LatLongRect.php: -------------------------------------------------------------------------------- 1 | minLatLng = $minLatLng; 24 | $this->maxLatLng = $maxLatLng; 25 | } 26 | 27 | /** 28 | * @return LatLng 29 | */ 30 | public function getMinLatLng() 31 | { 32 | return $this->minLatLng; 33 | } 34 | 35 | /** 36 | * @param LatLng $minLatLng 37 | */ 38 | public function setMinLatLng($minLatLng) 39 | { 40 | $this->minLatLng = $minLatLng; 41 | } 42 | 43 | /** 44 | * @return LatLng 45 | */ 46 | public function getMaxLatLng() 47 | { 48 | return $this->maxLatLng; 49 | } 50 | 51 | /** 52 | * @param LatLng $maxLatLng 53 | */ 54 | public function setMaxLatLng($maxLatLng) 55 | { 56 | $this->maxLatLng = $maxLatLng; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/Likelihood.php: -------------------------------------------------------------------------------- 1 | latLng = $latLng; 18 | } 19 | 20 | /** 21 | * @return LatLng 22 | */ 23 | public function getLatLng() 24 | { 25 | return $this->latLng; 26 | } 27 | 28 | /** 29 | * @param LatLng $latLng 30 | */ 31 | public function setLatLng($latLng) 32 | { 33 | $this->latLng = $latLng; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Annotation/Page.php: -------------------------------------------------------------------------------- 1 | property = $property; 36 | $this->width = $width; 37 | $this->height = $height; 38 | $this->blocks = $blocks; 39 | } 40 | 41 | /** 42 | * @return TextProperty 43 | */ 44 | public function getProperty() 45 | { 46 | return $this->property; 47 | } 48 | 49 | /** 50 | * @param TextProperty $property 51 | */ 52 | public function setProperty($property) 53 | { 54 | $this->property = $property; 55 | } 56 | 57 | /** 58 | * @return int 59 | */ 60 | public function getWidth() 61 | { 62 | return $this->width; 63 | } 64 | 65 | /** 66 | * @param int $width 67 | */ 68 | public function setWidth($width) 69 | { 70 | $this->width = $width; 71 | } 72 | 73 | /** 74 | * @return int 75 | */ 76 | public function getHeight() 77 | { 78 | return $this->height; 79 | } 80 | 81 | /** 82 | * @param int $height 83 | */ 84 | public function setHeight($height) 85 | { 86 | $this->height = $height; 87 | } 88 | 89 | /** 90 | * @return Block[] 91 | */ 92 | public function getBlocks() 93 | { 94 | return $this->blocks; 95 | } 96 | 97 | /** 98 | * @param Block[] $blocks 99 | */ 100 | public function setBlocks($blocks) 101 | { 102 | $this->blocks = $blocks; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/Annotation/Paragraph.php: -------------------------------------------------------------------------------- 1 | property = $property; 30 | $this->boundingBox = $boundingBox; 31 | $this->words = $words; 32 | } 33 | 34 | /** 35 | * @return TextProperty|null 36 | */ 37 | public function getProperty() 38 | { 39 | return $this->property; 40 | } 41 | 42 | /** 43 | * @param TextProperty|null $property 44 | */ 45 | public function setProperty($property) 46 | { 47 | $this->property = $property; 48 | } 49 | 50 | /** 51 | * @return BoundingPoly|null 52 | */ 53 | public function getBoundingBox() 54 | { 55 | return $this->boundingBox; 56 | } 57 | 58 | /** 59 | * @param BoundingPoly|null $boundingBox 60 | */ 61 | public function setBoundingBox($boundingBox) 62 | { 63 | $this->boundingBox = $boundingBox; 64 | } 65 | 66 | /** 67 | * @return Word[] 68 | */ 69 | public function getWords() 70 | { 71 | return $this->words; 72 | } 73 | 74 | /** 75 | * @param Word[] $words 76 | */ 77 | public function setWords($words) 78 | { 79 | $this->words = $words; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/Position.php: -------------------------------------------------------------------------------- 1 | x = $x; 30 | $this->y = $y; 31 | $this->z = $z; 32 | } 33 | 34 | /** 35 | * @return float 36 | */ 37 | public function getX() 38 | { 39 | return $this->x; 40 | } 41 | 42 | /** 43 | * @param float $x 44 | */ 45 | public function setX($x) 46 | { 47 | $this->x = $x; 48 | } 49 | 50 | /** 51 | * @return float 52 | */ 53 | public function getY() 54 | { 55 | return $this->y; 56 | } 57 | 58 | /** 59 | * @param float $y 60 | */ 61 | public function setY($y) 62 | { 63 | $this->y = $y; 64 | } 65 | 66 | /** 67 | * @return float 68 | */ 69 | public function getZ() 70 | { 71 | return $this->z; 72 | } 73 | 74 | /** 75 | * @param float $z 76 | */ 77 | public function setZ($z) 78 | { 79 | $this->z = $z; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/Property.php: -------------------------------------------------------------------------------- 1 | name = $name; 24 | $this->value = $value; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getName() 31 | { 32 | return $this->name; 33 | } 34 | 35 | /** 36 | * @param string $name 37 | */ 38 | public function setName($name) 39 | { 40 | $this->name = $name; 41 | } 42 | 43 | /** 44 | * @return string 45 | */ 46 | public function getValue() 47 | { 48 | return $this->value; 49 | } 50 | 51 | /** 52 | * @param string $value 53 | */ 54 | public function setValue($value) 55 | { 56 | $this->value = $value; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/SafeSearchAnnotation.php: -------------------------------------------------------------------------------- 1 | adult; 43 | } 44 | 45 | /** 46 | * @param string $adult 47 | */ 48 | public function setAdult($adult) 49 | { 50 | $this->adult = $adult; 51 | } 52 | 53 | /** 54 | * @return string 55 | */ 56 | public function getSpoof() 57 | { 58 | return $this->spoof; 59 | } 60 | 61 | /** 62 | * @param string $spoof 63 | */ 64 | public function setSpoof($spoof) 65 | { 66 | $this->spoof = $spoof; 67 | } 68 | 69 | /** 70 | * @return string 71 | */ 72 | public function getMedical() 73 | { 74 | return $this->medical; 75 | } 76 | 77 | /** 78 | * @param string $medical 79 | */ 80 | public function setMedical($medical) 81 | { 82 | $this->medical = $medical; 83 | } 84 | 85 | /** 86 | * @return string 87 | */ 88 | public function getViolence() 89 | { 90 | return $this->violence; 91 | } 92 | 93 | /** 94 | * @param string $violence 95 | */ 96 | public function setViolence($violence) 97 | { 98 | $this->violence = $violence; 99 | } 100 | 101 | /** 102 | * @return string 103 | */ 104 | public function getRacy() 105 | { 106 | return $this->racy; 107 | } 108 | 109 | /** 110 | * @param string $racy 111 | */ 112 | public function setRacy($racy) 113 | { 114 | $this->racy = $racy; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /src/Annotation/Symbol.php: -------------------------------------------------------------------------------- 1 | property = $property; 30 | $this->boundingBox = $boundingBox; 31 | $this->text = $text; 32 | } 33 | 34 | /** 35 | * @return TextProperty|null 36 | */ 37 | public function getProperty() 38 | { 39 | return $this->property; 40 | } 41 | 42 | /** 43 | * @param TextProperty|null $property 44 | */ 45 | public function setProperty($property) 46 | { 47 | $this->property = $property; 48 | } 49 | 50 | /** 51 | * @return BoundingPoly|null 52 | */ 53 | public function getBoundingBox() 54 | { 55 | return $this->boundingBox; 56 | } 57 | 58 | /** 59 | * @param BoundingPoly|null $boundingBox 60 | */ 61 | public function setBoundingBox($boundingBox) 62 | { 63 | $this->boundingBox = $boundingBox; 64 | } 65 | 66 | /** 67 | * @return string|null 68 | */ 69 | public function getText() 70 | { 71 | return $this->text; 72 | } 73 | 74 | /** 75 | * @param string|null $text 76 | */ 77 | public function setText($text) 78 | { 79 | $this->text = $text; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/TextAnnotation.php: -------------------------------------------------------------------------------- 1 | pages; 23 | } 24 | 25 | /** 26 | * @param Page[] $pages 27 | */ 28 | public function setPages($pages) 29 | { 30 | $this->pages = $pages; 31 | } 32 | 33 | /** 34 | * @return string 35 | */ 36 | public function getText() 37 | { 38 | return $this->text; 39 | } 40 | 41 | /** 42 | * @param string $text 43 | */ 44 | public function setText($text) 45 | { 46 | $this->text = $text; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Annotation/TextProperty.php: -------------------------------------------------------------------------------- 1 | detectedLanguages = $detectedLanguages; 24 | $this->detectedBreak = $detectedBreak; 25 | } 26 | 27 | /** 28 | * @return DetectedLanguage[] 29 | */ 30 | public function getDetectedLanguages() 31 | { 32 | return $this->detectedLanguages; 33 | } 34 | 35 | /** 36 | * @param DetectedLanguage[] $detectedLanguages 37 | */ 38 | public function setDetectedLanguages($detectedLanguages) 39 | { 40 | $this->detectedLanguages = $detectedLanguages; 41 | } 42 | 43 | /** 44 | * @return DetectedBreak 45 | */ 46 | public function getDetectedBreak() 47 | { 48 | return $this->detectedBreak; 49 | } 50 | 51 | /** 52 | * @param DetectedBreak $detectedBreak 53 | */ 54 | public function setDetectedBreak($detectedBreak) 55 | { 56 | $this->detectedBreak = $detectedBreak; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/Type.php: -------------------------------------------------------------------------------- 1 | x = $x; 24 | $this->y = $y; 25 | } 26 | 27 | /** 28 | * @return float|null 29 | */ 30 | public function getX() 31 | { 32 | return $this->x; 33 | } 34 | 35 | /** 36 | * @param float|null $x 37 | */ 38 | public function setX($x) 39 | { 40 | $this->x = $x; 41 | } 42 | 43 | /** 44 | * @return float|null 45 | */ 46 | public function getY() 47 | { 48 | return $this->y; 49 | } 50 | 51 | /** 52 | * @param float|null $y 53 | */ 54 | public function setY($y) 55 | { 56 | $this->y = $y; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/WebDetection.php: -------------------------------------------------------------------------------- 1 | webEntities; 38 | } 39 | 40 | /** 41 | * @param WebEntity[] $webEntities 42 | */ 43 | public function setWebEntities($webEntities) 44 | { 45 | $this->webEntities = $webEntities; 46 | } 47 | 48 | /** 49 | * @return WebImage[] 50 | */ 51 | public function getFullMatchingImages() 52 | { 53 | return $this->fullMatchingImages; 54 | } 55 | 56 | /** 57 | * @param WebImage[] $fullMatchingImages 58 | */ 59 | public function setFullMatchingImages($fullMatchingImages) 60 | { 61 | $this->fullMatchingImages = $fullMatchingImages; 62 | } 63 | 64 | /** 65 | * @return WebImage[] 66 | */ 67 | public function getPartialMatchingImages() 68 | { 69 | return $this->partialMatchingImages; 70 | } 71 | 72 | /** 73 | * @param WebImage[] $partialMatchingImages 74 | */ 75 | public function setPartialMatchingImages($partialMatchingImages) 76 | { 77 | $this->partialMatchingImages = $partialMatchingImages; 78 | } 79 | 80 | /** 81 | * @return WebImage[] 82 | */ 83 | public function getPagesWithMatchingImages() 84 | { 85 | return $this->pagesWithMatchingImages; 86 | } 87 | 88 | /** 89 | * @param WebImage[] $pagesWithMatchingImages 90 | */ 91 | public function setPagesWithMatchingImages($pagesWithMatchingImages) 92 | { 93 | $this->pagesWithMatchingImages = $pagesWithMatchingImages; 94 | } 95 | 96 | /** 97 | * @return WebImage[] 98 | */ 99 | public function getVisuallySimilarImages() 100 | { 101 | return $this->visuallySimilarImages; 102 | } 103 | 104 | /** 105 | * @param WebImage[] $visuallySimilarImages 106 | */ 107 | public function setVisuallySimilarImages($visuallySimilarImages) 108 | { 109 | $this->visuallySimilarImages = $visuallySimilarImages; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/Annotation/WebDetectionParams.php: -------------------------------------------------------------------------------- 1 | includeGeoResults = $includeGeoResults; 18 | } 19 | 20 | /** 21 | * @return bool 22 | */ 23 | public function isIncludeGeoResults() 24 | { 25 | return $this->includeGeoResults; 26 | } 27 | 28 | /** 29 | * @param bool $includeGeoResults 30 | */ 31 | public function setIncludeGeoResults($includeGeoResults) 32 | { 33 | $this->includeGeoResults = $includeGeoResults; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Annotation/WebEntity.php: -------------------------------------------------------------------------------- 1 | entityId = $entityId; 30 | $this->description = $description; 31 | $this->score = $score; 32 | } 33 | 34 | /** 35 | * @return string 36 | */ 37 | public function getEntityId() 38 | { 39 | return $this->entityId; 40 | } 41 | 42 | /** 43 | * @param string $entityId 44 | */ 45 | public function setEntityId($entityId) 46 | { 47 | $this->entityId = $entityId; 48 | } 49 | 50 | /** 51 | * @return float|null 52 | */ 53 | public function getScore() 54 | { 55 | return $this->score; 56 | } 57 | 58 | /** 59 | * @param float|null $score 60 | */ 61 | public function setScore($score) 62 | { 63 | $this->score = $score; 64 | } 65 | 66 | /** 67 | * @return string 68 | */ 69 | public function getDescription() 70 | { 71 | return $this->description; 72 | } 73 | 74 | /** 75 | * @param string $description 76 | */ 77 | public function setDescription($description) 78 | { 79 | $this->description = $description; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Annotation/WebImage.php: -------------------------------------------------------------------------------- 1 | url = $url; 24 | $this->score = $score; 25 | } 26 | 27 | /** 28 | * @return string 29 | */ 30 | public function getUrl() 31 | { 32 | return $this->url; 33 | } 34 | 35 | /** 36 | * @param string $url 37 | */ 38 | public function setUrl($url) 39 | { 40 | $this->url = $url; 41 | } 42 | 43 | /** 44 | * @return float|null 45 | */ 46 | public function getScore() 47 | { 48 | return $this->score; 49 | } 50 | 51 | /** 52 | * @param float|null $score 53 | */ 54 | public function setScore($score) 55 | { 56 | $this->score = $score; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Annotation/Word.php: -------------------------------------------------------------------------------- 1 | property = $property; 30 | $this->boundingBox = $boundingBox; 31 | $this->symbols = $symbols; 32 | } 33 | 34 | /** 35 | * @return TextProperty 36 | */ 37 | public function getProperty() 38 | { 39 | return $this->property; 40 | } 41 | 42 | /** 43 | * @param TextProperty $property 44 | */ 45 | public function setProperty($property) 46 | { 47 | $this->property = $property; 48 | } 49 | 50 | /** 51 | * @return BoundingPoly 52 | */ 53 | public function getBoundingBox() 54 | { 55 | return $this->boundingBox; 56 | } 57 | 58 | /** 59 | * @param BoundingPoly $boundingBox 60 | */ 61 | public function setBoundingBox($boundingBox) 62 | { 63 | $this->boundingBox = $boundingBox; 64 | } 65 | 66 | /** 67 | * @return Symbol[] 68 | */ 69 | public function getSymbols() 70 | { 71 | return $this->symbols; 72 | } 73 | 74 | /** 75 | * @param Symbol[] $symbols 76 | */ 77 | public function setSymbols($symbols) 78 | { 79 | $this->symbols = $symbols; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Exception/ImageException.php: -------------------------------------------------------------------------------- 1 | availableFeatureMap)) { 56 | throw new UnknownFeatureException('Could not find feature with name "' . $feature . '"'); 57 | } 58 | 59 | $this->feature = $feature; 60 | $this->maxResults = (int)$maxResults; 61 | } 62 | 63 | /** 64 | * @return string 65 | */ 66 | public function getFeature() 67 | { 68 | return $this->feature; 69 | } 70 | 71 | /** 72 | * @return int 73 | */ 74 | public function getMaxResults() 75 | { 76 | return $this->maxResults; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/Hydrator/AnnotateImageHydrator.php: -------------------------------------------------------------------------------- 1 | EntityAnnotation::class, 23 | 'labelAnnotations' => EntityAnnotation::class, 24 | 'textAnnotations' => EntityAnnotation::class, 25 | 'landmarkAnnotations' => EntityAnnotation::class, 26 | 'imagePropertiesAnnotation' => ImagePropertiesAnnotation::class, 27 | 'safeSearchAnnotation' => SafeSearchAnnotation::class, 28 | 'cropHintsAnnotation' => CropHintsAnnotation::class, 29 | 'faceAnnotations' => FaceAnnotation::class, 30 | 'webDetection' => WebDetection::class, 31 | 'fullTextAnnotation' => TextAnnotation::class, 32 | 'error' => Error::class, 33 | ]; 34 | 35 | /** 36 | * @var array 37 | */ 38 | protected $hydratorClassMap = [ 39 | 'logoAnnotations' => SubAnnotationHydrator::class, 40 | 'labelAnnotations' => SubAnnotationHydrator::class, 41 | 'textAnnotations' => SubAnnotationHydrator::class, 42 | 'landmarkAnnotations' => SubAnnotationHydrator::class, 43 | 'faceAnnotations' => SubAnnotationHydrator::class, 44 | 'imagePropertiesAnnotation' => AnnotationHydrator::class, 45 | 'safeSearchAnnotation' => AnnotationHydrator::class, 46 | 'cropHintsAnnotation' => AnnotationHydrator::class, 47 | 'webDetection' => WebDetectionHydrator::class, 48 | 'fullTextAnnotation' => TextAnnotationHydrator::class, 49 | 'error' => AnnotationHydrator::class, 50 | ]; 51 | 52 | /** 53 | * @var bool 54 | */ 55 | protected $underscoreSeparatedKeys = false; 56 | 57 | /** 58 | * @param object $object 59 | * @return array 60 | */ 61 | public function extract($object) 62 | { 63 | $array = []; 64 | $class = new \ReflectionClass($object); 65 | foreach ($class->getMethods() as $method) { 66 | $methodName = $method->name; 67 | if (!$this->canExtractMethod($object, $methodName)) { 68 | continue; 69 | } 70 | 71 | $annotation = lcfirst(substr($methodName, 3)); 72 | 73 | /** @var HydratorInterface $hydrator */ 74 | $hydrator = new $this->hydratorClassMap[$annotation]; 75 | $array[$annotation] = array_filter($this->extractAnnotation($object->$methodName(), $hydrator)); 76 | } 77 | 78 | return $array; 79 | } 80 | 81 | /** 82 | * @param object $object 83 | * @param string $methodName 84 | * @return bool 85 | */ 86 | protected function canExtractMethod($object, $methodName) 87 | { 88 | return substr($methodName, 0, 3) === 'get' 89 | && isset($this->hydratorClassMap[lcfirst(substr($methodName, 3))]) 90 | && !!$object->$methodName(); 91 | } 92 | 93 | /** 94 | * @param array|object $arrayObject 95 | * @param HydratorInterface $hydrator 96 | * @return array 97 | */ 98 | protected function extractAnnotation($arrayObject, HydratorInterface $hydrator) 99 | { 100 | if (is_object($arrayObject)) { 101 | return $hydrator->extract($arrayObject); 102 | } 103 | 104 | $map = []; 105 | foreach ($arrayObject as $annotation) { 106 | $map[] = $hydrator->extract($annotation); 107 | } 108 | 109 | return $map; 110 | } 111 | 112 | /** 113 | * @param array $data 114 | * @param object $object 115 | * @return object 116 | */ 117 | public function hydrate(array $data, $object) 118 | { 119 | foreach ($data as $annotation => $value) { 120 | if (!isset($this->hydratorClassMap[$annotation], $this->annotationClassMap[$annotation])) { 121 | continue; 122 | } 123 | 124 | $hydrator = new $this->hydratorClassMap[$annotation]; 125 | if (!$hydrator instanceof HydratorInterface) { 126 | throw new LogicException('Hydrator does not implement HydratorInterface'); 127 | } 128 | 129 | $annotationObject = new $this->annotationClassMap[$annotation]; 130 | $setter = 'set' . ucfirst($annotation); 131 | 132 | $object->$setter($hydrator->hydrate($value, $annotationObject)); 133 | } 134 | 135 | return $object; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /src/Hydrator/AnnotationHydrator.php: -------------------------------------------------------------------------------- 1 | addStrategy('boundingPoly', new Strategy\BoundingPolyStrategy); 14 | $this->addStrategy('fdBoundingPoly', new Strategy\BoundingPolyStrategy); 15 | $this->addStrategy('dominantColors', new Strategy\DominantColorsStrategy()); 16 | $this->addStrategy('landmarks', new Strategy\LandmarkStrategy()); 17 | $this->addStrategy('properties', new Strategy\PropertyStrategy()); 18 | $this->addStrategy('locations', new Strategy\LocationStrategy()); 19 | $this->addStrategy('webEntities', new Strategy\WebEntitiesStrategy()); 20 | $this->addStrategy('cropHints', new Strategy\CropHintStrategy()); 21 | $this->addStrategy('latLongRect', new Strategy\LatLongRectStrategy()); 22 | $this->addStrategy('cropHintsParams', new Strategy\CropHintsParamsStrategy()); 23 | $this->addStrategy('webDetectionParams', new Strategy\WebDetectionParamsStrategy()); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/BlocksStrategy.php: -------------------------------------------------------------------------------- 1 | textPropertyStrategy = new TextPropertyStrategy; 28 | $this->boundingPolyStrategy = new BoundingPolyStrategy; 29 | $this->paragraphsStrategy = new ParagraphsStrategy; 30 | } 31 | 32 | /** 33 | * @param Block[] $value 34 | * @return array 35 | */ 36 | public function extract($value) 37 | { 38 | return array_map(function(Block $blockEntity) { 39 | return array_filter([ 40 | 'property' => $this->textPropertyStrategy->extract($blockEntity->getProperty()), 41 | 'boundingBox' => $this->boundingPolyStrategy->extract($blockEntity->getBoundingBox()), 42 | 'paragraphs' => $this->paragraphsStrategy->extract($blockEntity->getParagraphs()), 43 | 'blockType' => $blockEntity->getBlockType(), 44 | ]); 45 | }, $value); 46 | } 47 | 48 | /** 49 | * @param array $value 50 | * @return Block[] 51 | */ 52 | public function hydrate($value) 53 | { 54 | $blockEntities = []; 55 | 56 | foreach ($value as $blockEntityInfo) { 57 | $blockEntities[] = new Block( 58 | isset($blockEntityInfo['property']) ? $this->textPropertyStrategy->hydrate($blockEntityInfo['property']) : null, 59 | isset($blockEntityInfo['boundingBox']) ? $this->boundingPolyStrategy->hydrate($blockEntityInfo['boundingBox']) : null, 60 | isset($blockEntityInfo['paragraphs']) ? $this->paragraphsStrategy->hydrate($blockEntityInfo['paragraphs']) : [], 61 | isset($blockEntityInfo['blockType']) ? $blockEntityInfo['blockType'] : Block::TYPE_UNKNOWN 62 | ); 63 | } 64 | 65 | return $blockEntities; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/BoundingPolyStrategy.php: -------------------------------------------------------------------------------- 1 | getVertices() : []; 18 | $verticleMap = array_map(function(Vertex $vertex) { 19 | return array_filter([ 20 | 'x' => $vertex->getX(), 21 | 'y' => $vertex->getY(), 22 | ]); 23 | }, $verticles); 24 | 25 | return [ 26 | 'vertices' => $verticleMap 27 | ]; 28 | } 29 | 30 | /** 31 | * @param array $value 32 | * @return BoundingPoly 33 | */ 34 | public function hydrate($value) 35 | { 36 | $boundingPoly = new BoundingPoly; 37 | foreach ($value['vertices'] as $vertex) { 38 | $x = isset($vertex['x']) ? $vertex['x'] : null; 39 | $y = isset($vertex['y']) ? $vertex['y'] : null; 40 | 41 | $boundingPoly->addVertex(new Vertex($x, $y)); 42 | } 43 | 44 | return $boundingPoly; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/CropHintStrategy.php: -------------------------------------------------------------------------------- 1 | boundingPolyStrategy = new BoundingPolyStrategy; 18 | } 19 | 20 | /** 21 | * @param CropHint[] $value 22 | * @return array 23 | */ 24 | public function extract($value) 25 | { 26 | return array_map(function(CropHint $cropHint) { 27 | return array_filter([ 28 | 'boundingPoly' => $this->boundingPolyStrategy->extract($cropHint->getBoundingPoly()), 29 | 'confidence' => $cropHint->getConfidence(), 30 | 'importanceFraction' => $cropHint->getImportanceFraction(), 31 | ]); 32 | }, $value); 33 | } 34 | 35 | /** 36 | * @param array $value 37 | * @return CropHint[] 38 | */ 39 | public function hydrate($value) 40 | { 41 | $cropHints = []; 42 | 43 | foreach ($value as $cropHintInfo) { 44 | $cropHints[] = new CropHint( 45 | $this->boundingPolyStrategy->hydrate($cropHintInfo['boundingPoly']), 46 | isset($cropHintInfo['confidence']) ? $cropHintInfo['confidence'] : null, 47 | isset($cropHintInfo['importanceFraction']) ? $cropHintInfo['importanceFraction'] : null 48 | ); 49 | } 50 | 51 | return $cropHints; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/CropHintsParamsStrategy.php: -------------------------------------------------------------------------------- 1 | $value->getAspectRatios()] : null; 17 | } 18 | 19 | /** 20 | * @param array $value 21 | * @return CropHintsParams|null 22 | */ 23 | public function hydrate($value) 24 | { 25 | return $value ? new CropHintsParams($value['aspectRatios']) : null; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/DetectedBreakStrategy.php: -------------------------------------------------------------------------------- 1 | $value->getType(), 18 | 'isPrefix' => $value->isPrefix(), 19 | ]); 20 | } 21 | 22 | /** 23 | * @param array $value 24 | * @return DetectedBreak 25 | */ 26 | public function hydrate($value) 27 | { 28 | return new DetectedBreak($value['type'], isset($value['isPrefix']) ? $value['isPrefix'] : false); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/DetectedLanguagesStrategy.php: -------------------------------------------------------------------------------- 1 | $detectedLanguage->getLanguageCode(), 19 | 'confidence' => $detectedLanguage->getConfidence(), 20 | ]); 21 | }, $value); 22 | } 23 | 24 | /** 25 | * @param array $value 26 | * @return DetectedLanguage[] 27 | */ 28 | public function hydrate($value) 29 | { 30 | $detectedLanguageEntities = []; 31 | 32 | foreach ($value as $detectedLanguageInfo) { 33 | $detectedLanguageEntities[] = new DetectedLanguage( 34 | $detectedLanguageInfo['languageCode'], 35 | isset($detectedLanguageInfo['confidence']) ? $detectedLanguageInfo['confidence'] : null 36 | ); 37 | } 38 | 39 | return $detectedLanguageEntities; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/DominantColorsStrategy.php: -------------------------------------------------------------------------------- 1 | [ 20 | 'red' => $dominantColor->getColor()->getRed(), 21 | 'green' => $dominantColor->getColor()->getGreen(), 22 | 'blue' => $dominantColor->getColor()->getBlue(), 23 | ], 24 | 'score' => $dominantColor->getScore(), 25 | 'pixelFraction' => $dominantColor->getPixelFraction(), 26 | ]; 27 | }, $value); 28 | 29 | return ['colors' => $colorMap]; 30 | } 31 | 32 | /** 33 | * @param array $value 34 | * @return DominantColor[] 35 | */ 36 | public function hydrate($value) 37 | { 38 | $dominantColors = []; 39 | 40 | foreach ($value['colors'] as $colorInfo) { 41 | $dominantColor = new DominantColor(); 42 | 43 | $colorArray = $colorInfo['color']; 44 | $color = new Color($colorArray['red'], $colorArray['green'], $colorArray['blue']); 45 | 46 | $dominantColor->setColor($color); 47 | $dominantColor->setPixelFraction($colorInfo['pixelFraction']); 48 | $dominantColor->setScore($colorInfo['score']); 49 | 50 | $dominantColors[] = $dominantColor; 51 | } 52 | 53 | return $dominantColors; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/LandmarkStrategy.php: -------------------------------------------------------------------------------- 1 | $landmark->getType(), 20 | 'position' => [ 21 | 'x' => $landmark->getPosition()->getX(), 22 | 'y' => $landmark->getPosition()->getY(), 23 | 'z' => $landmark->getPosition()->getZ() 24 | ] 25 | ]; 26 | }, $value); 27 | } 28 | 29 | /** 30 | * @param array $value 31 | * @return Landmark[] 32 | */ 33 | public function hydrate($value) 34 | { 35 | $landmarks = []; 36 | 37 | foreach ($value as $landmarkInfo) { 38 | $position = $landmarkInfo['position']; 39 | 40 | $landmark = new Landmark(); 41 | $landmark->setType($landmarkInfo['type']); 42 | $landmark->setPosition( 43 | new Position($position['x'], $position['y'], $position['z']) 44 | ); 45 | 46 | $landmarks[] = $landmark; 47 | } 48 | 49 | return $landmarks; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/LatLongRectStrategy.php: -------------------------------------------------------------------------------- 1 | getMinLatLng(); 22 | $maxLatLng = $value->getMaxLatLng(); 23 | 24 | return array_filter([ 25 | 'minLatLng' => array_filter([ 26 | 'latitude' => $minLatLng ? $minLatLng->getLatitude() : null, 27 | 'longitude' => $minLatLng ? $minLatLng->getLongitude() : null, 28 | ]), 29 | 'maxLatLng' => array_filter([ 30 | 'latitude' => $maxLatLng ? $maxLatLng->getLatitude() : null, 31 | 'longitude' => $maxLatLng ? $maxLatLng->getLongitude() : null, 32 | ]) 33 | ]); 34 | } 35 | 36 | /** 37 | * @param array $value 38 | * @return LatLongRect|null 39 | */ 40 | public function hydrate($value) 41 | { 42 | $minLatLng = $this->getIfExists($value, 'minLatLng'); 43 | $maxLatLng = $this->getIfExists($value, 'maxLatLng'); 44 | 45 | if (!$minLatLng && !$maxLatLng) { 46 | return null; 47 | } 48 | 49 | return new LatLongRect( 50 | new LatLng($this->getIfExists($minLatLng, 'latitude'), $this->getIfExists($minLatLng, 'longitude')), 51 | new LatLng($this->getIfExists($maxLatLng, 'latitude'), $this->getIfExists($maxLatLng, 'longitude')) 52 | ); 53 | } 54 | 55 | /** 56 | * @param array $variable 57 | * @param string $key 58 | * @return mixed 59 | */ 60 | protected function getIfExists($variable, $key) 61 | { 62 | return $variable && isset($variable[$key]) ? $variable[$key] : null; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/LocationStrategy.php: -------------------------------------------------------------------------------- 1 | [ 20 | 'latitude' => $location->getLatLng()->getLatitude(), 21 | 'longitude' => $location->getLatLng()->getLongitude() 22 | ] 23 | ]; 24 | }, $value); 25 | } 26 | 27 | /** 28 | * @param array $value 29 | * @return Location[] 30 | */ 31 | public function hydrate($value) 32 | { 33 | $locations = []; 34 | 35 | foreach ($value as $locationInfo) { 36 | $latLng = $locationInfo['latLng']; 37 | $locations[] = new Location(new LatLng($latLng['latitude'], $latLng['longitude'])); 38 | } 39 | 40 | return $locations; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/PagesStrategy.php: -------------------------------------------------------------------------------- 1 | textPropertyStrategy = new TextPropertyStrategy; 23 | $this->blocksStrategy = new BlocksStrategy; 24 | } 25 | 26 | /** 27 | * @param Page[] $value 28 | * @return array 29 | */ 30 | public function extract($value) 31 | { 32 | return array_map(function(Page $page) { 33 | return array_filter([ 34 | 'property' => $this->textPropertyStrategy->extract($page->getProperty()), 35 | 'width' => $page->getWidth(), 36 | 'height' => $page->getHeight(), 37 | 'blocks' => $this->blocksStrategy->extract($page->getBlocks()) 38 | ]); 39 | }, $value); 40 | } 41 | 42 | /** 43 | * @param array $value 44 | * @return Page[] 45 | */ 46 | public function hydrate($value) 47 | { 48 | $pageEntities = []; 49 | 50 | foreach ($value as $pageEntityInfo) { 51 | $pageEntities[] = new Page( 52 | $this->textPropertyStrategy->hydrate($pageEntityInfo['property']), 53 | $pageEntityInfo['width'], 54 | $pageEntityInfo['height'], 55 | $this->blocksStrategy->hydrate($pageEntityInfo['blocks']) 56 | ); 57 | } 58 | 59 | return $pageEntities; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/ParagraphsStrategy.php: -------------------------------------------------------------------------------- 1 | textPropertyStrategy = new TextPropertyStrategy; 28 | $this->boundingPolyStrategy = new BoundingPolyStrategy; 29 | $this->wordsStrategy = new WordsStrategy; 30 | } 31 | 32 | /** 33 | * @param Paragraph[] $value 34 | * @return array 35 | */ 36 | public function extract($value) 37 | { 38 | return array_map(function(Paragraph $paragraphEntity) { 39 | $textProperty = $paragraphEntity->getProperty() 40 | ? $this->textPropertyStrategy->extract($paragraphEntity->getProperty()) 41 | : null; 42 | 43 | $boundingBox = $paragraphEntity->getBoundingBox() 44 | ? $this->boundingPolyStrategy->extract($paragraphEntity->getBoundingBox()) 45 | : null; 46 | 47 | $words = $paragraphEntity->getWords() 48 | ? $this->wordsStrategy->extract($paragraphEntity->getWords()) 49 | : null; 50 | 51 | 52 | return array_filter([ 53 | 'property' => $textProperty, 54 | 'boundingBox' => $boundingBox, 55 | 'words' => $words, 56 | ]); 57 | }, $value); 58 | } 59 | 60 | /** 61 | * @param array $value 62 | * @return Paragraph[] 63 | */ 64 | public function hydrate($value) 65 | { 66 | $paragraphEntities = []; 67 | foreach ($value as $paragraphEntityInfo) { 68 | $textProperty = isset($paragraphEntityInfo['property']) 69 | ? $this->textPropertyStrategy->hydrate($paragraphEntityInfo['property']) 70 | : null; 71 | 72 | $boundingBox = isset($paragraphEntityInfo['boundingBox']) 73 | ? $this->boundingPolyStrategy->hydrate($paragraphEntityInfo['boundingBox']) 74 | : null; 75 | 76 | $words = isset($paragraphEntityInfo['words']) 77 | ? $this->wordsStrategy->hydrate($paragraphEntityInfo['words']) 78 | : null; 79 | 80 | $paragraphEntities[] = new Paragraph($textProperty, $boundingBox, $words); 81 | } 82 | 83 | return $paragraphEntities; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/PropertyStrategy.php: -------------------------------------------------------------------------------- 1 | $property->getName(), 19 | 'value' => $property->getValue(), 20 | ]; 21 | }, $value); 22 | } 23 | 24 | /** 25 | * @param array $value 26 | * @return Property[] 27 | */ 28 | public function hydrate($value) 29 | { 30 | $properties = []; 31 | 32 | foreach ($value as $propertyInfo) { 33 | $properties[] = new Property($propertyInfo['name'], $propertyInfo['value']); 34 | } 35 | 36 | return $properties; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/SymbolsStrategy.php: -------------------------------------------------------------------------------- 1 | textPropertyStrategy = new TextPropertyStrategy; 23 | $this->boundingPolyStrategy = new BoundingPolyStrategy; 24 | } 25 | 26 | /** 27 | * @param Symbol[] $value 28 | * @return array 29 | */ 30 | public function extract($value) 31 | { 32 | return array_map(function(Symbol $symbolEntity) { 33 | $textProperty = $symbolEntity->getProperty() 34 | ? $this->textPropertyStrategy->extract($symbolEntity->getProperty()) 35 | : null; 36 | 37 | $boundingBox = $symbolEntity->getBoundingBox() 38 | ? $this->boundingPolyStrategy->extract($symbolEntity->getBoundingBox()) 39 | : null; 40 | 41 | return array_filter([ 42 | 'property' => $textProperty, 43 | 'boundingBox' => $boundingBox, 44 | 'text' => $symbolEntity->getText(), 45 | ]); 46 | }, $value); 47 | } 48 | 49 | /** 50 | * @param array $value 51 | * @return Symbol[] 52 | */ 53 | public function hydrate($value) 54 | { 55 | $symbolEntities = []; 56 | 57 | foreach ($value as $symbolEntityInfo) { 58 | $textProperty = isset($symbolEntityInfo['property']) 59 | ? $this->textPropertyStrategy->hydrate($symbolEntityInfo['property']) 60 | : null; 61 | 62 | $boundingBox = isset($symbolEntityInfo['boundingBox']) 63 | ? $this->boundingPolyStrategy->hydrate($symbolEntityInfo['boundingBox']) 64 | : null; 65 | 66 | $symbolEntities[] = new Symbol( 67 | $textProperty, 68 | $boundingBox, 69 | isset($symbolEntityInfo['text']) ? $symbolEntityInfo['text'] : null 70 | ); 71 | } 72 | 73 | return $symbolEntities; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/TextPropertyStrategy.php: -------------------------------------------------------------------------------- 1 | detectedLanguagesStrategy = new DetectedLanguagesStrategy; 24 | $this->detectedBreakStrategy = new DetectedBreakStrategy; 25 | } 26 | 27 | /** 28 | * @param TextProperty $value 29 | * @return array 30 | */ 31 | public function extract($value) 32 | { 33 | return array_filter([ 34 | 'detectedLanguages' => $this->detectedLanguagesStrategy->extract($value->getDetectedLanguages()), 35 | 'detectedBreak' => $this->detectedBreakStrategy->extract($value->getDetectedBreak()), 36 | ]); 37 | 38 | } 39 | 40 | /** 41 | * @param array $value 42 | * @return TextProperty 43 | */ 44 | public function hydrate($value) 45 | { 46 | return new TextProperty( 47 | isset($value['detectedLanguages']) ? $this->detectedLanguagesStrategy->hydrate($value['detectedLanguages']) : [], 48 | isset($value['detectedBreak']) ? $this->detectedBreakStrategy->hydrate($value['detectedBreak']) : null 49 | ); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/WebDetectionParamsStrategy.php: -------------------------------------------------------------------------------- 1 | !!$value->isIncludeGeoResults()] : null; 18 | } 19 | 20 | /** 21 | * @param array $value 22 | * @return WebDetectionParams|null 23 | */ 24 | public function hydrate($value) 25 | { 26 | return $value ? new WebDetectionParams(!!$value['includeGeoResults']) : null; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/WebEntitiesStrategy.php: -------------------------------------------------------------------------------- 1 | $webEntity->getEntityId(), 20 | 'score' => $webEntity->getScore(), 21 | 'description' => $webEntity->getDescription(), 22 | ]); 23 | }, $value); 24 | } 25 | 26 | /** 27 | * @param array $value 28 | * @return WebEntity[] 29 | */ 30 | public function hydrate($value) 31 | { 32 | $webEntities = []; 33 | 34 | foreach ($value as $webEntityInfo) { 35 | $webEntities[] = new WebEntity( 36 | $webEntityInfo['entityId'], 37 | isset($webEntityInfo['description']) ? $webEntityInfo['description'] : null, 38 | isset($webEntityInfo['score']) ? $webEntityInfo['score'] : null 39 | ); 40 | } 41 | 42 | return $webEntities; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/WebImagesStrategy.php: -------------------------------------------------------------------------------- 1 | $webImage->getUrl(), 19 | 'score' => $webImage->getScore(), 20 | ]); 21 | }, $value); 22 | } 23 | 24 | /** 25 | * @param array $value 26 | * @return WebImage[] 27 | */ 28 | public function hydrate($value) 29 | { 30 | $webImages = []; 31 | 32 | foreach ($value as $webImageInfo) { 33 | $webImages[] = new WebImage($webImageInfo['url'], isset($webImageInfo['score']) ? $webImageInfo['score'] : null); 34 | } 35 | 36 | return $webImages; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/WebPagesStrategy.php: -------------------------------------------------------------------------------- 1 | $webPage->getUrl(), 20 | 'score' => $webPage->getScore(), 21 | ]); 22 | }, $value); 23 | } 24 | 25 | /** 26 | * @param array $value 27 | * @return WebPage[] 28 | */ 29 | public function hydrate($value) 30 | { 31 | $webPages = []; 32 | 33 | foreach ($value as $webPageInfo) { 34 | $webPages[] = new WebPage($webPageInfo['url'], isset($webPageInfo['score']) ? $webPageInfo['score'] : null); 35 | } 36 | 37 | return $webPages; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Hydrator/Strategy/WordsStrategy.php: -------------------------------------------------------------------------------- 1 | textPropertyStrategy = new TextPropertyStrategy; 29 | $this->boundingPolyStrategy = new BoundingPolyStrategy; 30 | $this->symbolsStrategy = new SymbolsStrategy; 31 | } 32 | 33 | /** 34 | * @param Word[] $value 35 | * @return array 36 | */ 37 | public function extract($value) 38 | { 39 | return array_map(function(Word $wordEntity) { 40 | $textProperty = $wordEntity->getProperty() 41 | ? $this->textPropertyStrategy->extract($wordEntity->getProperty()) 42 | : null; 43 | 44 | $boundingBox = $wordEntity->getBoundingBox() 45 | ? $this->boundingPolyStrategy->extract($wordEntity->getBoundingBox()) 46 | : null; 47 | 48 | $symbols = $wordEntity->getSymbols() 49 | ? $this->symbolsStrategy->extract($wordEntity->getSymbols()) 50 | : null; 51 | 52 | return array_filter([ 53 | 'property' => $textProperty, 54 | 'boundingBox' => $boundingBox, 55 | 'symbols' => $symbols, 56 | ]); 57 | }, $value); 58 | } 59 | 60 | /** 61 | * @param array $value 62 | * @return Word[] 63 | */ 64 | public function hydrate($value) 65 | { 66 | $wordEntities = []; 67 | 68 | foreach ($value as $wordEntityInfo) { 69 | $textProperty = isset($wordEntityInfo['property']) 70 | ? $this->textPropertyStrategy->hydrate($wordEntityInfo['property']) 71 | : null; 72 | 73 | $boundingBox = isset($wordEntityInfo['boundingBox']) 74 | ? $this->boundingPolyStrategy->hydrate($wordEntityInfo['boundingBox']) 75 | : null; 76 | 77 | $symbols = isset($wordEntityInfo['symbols']) 78 | ? $this->symbolsStrategy->hydrate($wordEntityInfo['symbols']) 79 | : null; 80 | 81 | $wordEntities[] = new Word( 82 | $textProperty, 83 | $boundingBox, 84 | $symbols 85 | ); 86 | } 87 | 88 | return $wordEntities; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/Hydrator/SubAnnotationHydrator.php: -------------------------------------------------------------------------------- 1 | extract($object); 20 | } 21 | 22 | /** 23 | * Hydrate $object with the provided $data. 24 | * 25 | * @param array $data 26 | * @param object $object 27 | * @return object[] 28 | */ 29 | public function hydrate(array $data, $object) 30 | { 31 | $array = []; 32 | $hydrator = new AnnotationHydrator(); 33 | 34 | foreach ($data as $value) { 35 | $clonedObject = clone $object; 36 | $array[] = $hydrator->hydrate($value, $clonedObject); 37 | } 38 | 39 | return $array; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Hydrator/TextAnnotationHydrator.php: -------------------------------------------------------------------------------- 1 | addStrategy('pages', new Strategy\PagesStrategy()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/Hydrator/WebDetectionHydrator.php: -------------------------------------------------------------------------------- 1 | addStrategy('webEntities', new Strategy\WebEntitiesStrategy()); 14 | $this->addStrategy('fullMatchingImages', new Strategy\WebImagesStrategy()); 15 | $this->addStrategy('partialMatchingImages', new Strategy\WebImagesStrategy()); 16 | $this->addStrategy('pagesWithMatchingImages', new Strategy\WebPagesStrategy()); 17 | $this->addStrategy('visuallySimilarImages', new Strategy\WebImagesStrategy()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Image.php: -------------------------------------------------------------------------------- 1 | setImageFromPath($path); 30 | } 31 | } 32 | 33 | /** 34 | * @param string $path 35 | */ 36 | public function setImageFromPath($path) 37 | { 38 | $imageData = @file_get_contents($path); 39 | if (!$imageData) { 40 | throw new ImageException('Could not load the given image'); 41 | } 42 | $this->value = $this->image = base64_encode($imageData); 43 | } 44 | 45 | /** 46 | * @return string 47 | */ 48 | public function getImage() 49 | { 50 | return $this->image; 51 | } 52 | 53 | /** 54 | * @param string $image 55 | */ 56 | public function setImage($image) 57 | { 58 | parent::setValue($image); 59 | 60 | $this->image = $this->value; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Request/Image/AbstractImage.php: -------------------------------------------------------------------------------- 1 | value; 18 | } 19 | 20 | /** 21 | * @return string 22 | */ 23 | abstract public function getType(); 24 | } 25 | -------------------------------------------------------------------------------- /src/Request/Image/Base64Image.php: -------------------------------------------------------------------------------- 1 | setValue($value); 16 | } 17 | } 18 | 19 | /** 20 | * @param string $value 21 | */ 22 | public function setValue($value) 23 | { 24 | if (base64_encode(base64_decode($value, true)) !== $value){ 25 | throw new ImageException('The given image is not in a valid Base64 string'); 26 | } 27 | 28 | $this->value = $value; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getType() 35 | { 36 | return 'content'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Request/Image/BinaryImage.php: -------------------------------------------------------------------------------- 1 | setValue($value); 13 | } 14 | 15 | /** 16 | * @param string $value 17 | */ 18 | public function setValue($value) 19 | { 20 | $this->value = base64_encode($value); 21 | } 22 | 23 | /** 24 | * @return string 25 | */ 26 | public function getType() 27 | { 28 | return 'content'; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Request/Image/GoogleCloudImage.php: -------------------------------------------------------------------------------- 1 | bucket = str_replace('gs://', '', $bucket); 19 | $this->setObjectName($objectName); 20 | } 21 | 22 | /** 23 | * @param string $objectName 24 | */ 25 | public function setObjectName($objectName) 26 | { 27 | $this->value = $objectName; 28 | } 29 | 30 | /** 31 | * @return array 32 | */ 33 | public function getValue() 34 | { 35 | return ['imageUri' => 'gs://' . $this->bucket . '/' . $this->value]; 36 | } 37 | 38 | /** 39 | * @return string 40 | */ 41 | public function getType() 42 | { 43 | return 'source'; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/Request/Image/ImageInterface.php: -------------------------------------------------------------------------------- 1 | setImageFromPath($path); 16 | } 17 | } 18 | 19 | /** 20 | * @param string $path 21 | */ 22 | public function setImageFromPath($path) 23 | { 24 | $imageData = @file_get_contents($path); 25 | if (!$imageData) { 26 | throw new ImageException('Could not load the given image'); 27 | } 28 | 29 | $this->value = base64_encode($imageData); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Request/Image/RemoteImage.php: -------------------------------------------------------------------------------- 1 | value = $remoteUrl; 13 | } 14 | 15 | /** 16 | * @param string $remoteUrl 17 | */ 18 | public function setRemoteUrl($remoteUrl) 19 | { 20 | $this->value = $remoteUrl; 21 | } 22 | 23 | /** 24 | * @return array 25 | */ 26 | public function getValue() 27 | { 28 | return ['imageUri' => $this->value]; 29 | } 30 | 31 | /** 32 | * @return string 33 | */ 34 | public function getType() 35 | { 36 | return 'source'; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Request/VisionRequest.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 63 | $this->features = $features; 64 | $this->image = $image; 65 | $this->imageContext = $imageContext ?: new ImageContext; 66 | } 67 | 68 | /** 69 | * @param Client|null $client 70 | */ 71 | public function send(Client $client = null) 72 | { 73 | $client = $client ?: new Client; 74 | 75 | try { 76 | $response = $client->post( 77 | $this->getRequestUrl(), 78 | [ 79 | 'content-type' => 'application/json', 80 | 'body' => json_encode($this->getPayload()), 81 | ] 82 | ); 83 | 84 | $this->rawResponse = $response->getBody()->getContents(); 85 | } catch (ClientException $e) { 86 | $this->clientException = $e; 87 | } 88 | } 89 | 90 | /** 91 | * @return AnnotateImageResponse 92 | */ 93 | public function getAnnotateImageResponse() 94 | { 95 | if ($this->clientException) { 96 | return $this->getResponseFromException($this->clientException); 97 | } 98 | 99 | $content = json_decode($this->rawResponse, true); 100 | return $this->getResponseFromArray($content['responses'][0]); 101 | } 102 | 103 | /** 104 | * @return string 105 | */ 106 | public function getRawResponse() 107 | { 108 | return $this->rawResponse; 109 | } 110 | 111 | /** 112 | * @return string 113 | */ 114 | public function getRequestUrl() 115 | { 116 | $visionUrl = self::VISION_ANNOTATE_PREFIX . $this->apiKey; 117 | return str_replace('/' . self::VISION_VERSION . '/', '/' . $this->getVersion() . '/', $visionUrl); 118 | } 119 | 120 | /** 121 | * @return string 122 | */ 123 | public function getVersion() 124 | { 125 | return $this->version; 126 | } 127 | 128 | /** 129 | * @param string $version 130 | */ 131 | public function setVersion($version) 132 | { 133 | $this->version = $version; 134 | } 135 | 136 | /** 137 | * @return array 138 | */ 139 | protected function getPayload() 140 | { 141 | return [ 142 | 'requests' => [ 143 | [ 144 | 'image' => [ 145 | $this->image->getType() => $this->image->getValue(), 146 | ], 147 | 'features' => $this->getMappedFeatures(), 148 | 'imageContext' => $this->extractImageContext() ?: null 149 | ], 150 | ], 151 | ]; 152 | } 153 | 154 | /** 155 | * @return array 156 | */ 157 | protected function getMappedFeatures() 158 | { 159 | return array_map( 160 | function(Feature $feature) { 161 | return [ 162 | 'type' => $feature->getFeature(), 163 | 'maxResults' => $feature->getMaxResults(), 164 | ]; 165 | }, 166 | $this->features 167 | ); 168 | } 169 | 170 | /** 171 | * @return array 172 | */ 173 | protected function extractImageContext() 174 | { 175 | return array_filter( 176 | (new AnnotationHydrator)->extract($this->imageContext) 177 | ); 178 | } 179 | 180 | /** 181 | * @param array $response 182 | * @return AnnotateImageResponse|object 183 | */ 184 | protected function getResponseFromArray(array $response) 185 | { 186 | return (new AnnotateImageHydrator)->hydrate($response, new AnnotateImageResponse); 187 | } 188 | 189 | /** 190 | * @param ClientException $exception 191 | * @return AnnotateImageResponse 192 | */ 193 | protected function getResponseFromException(ClientException $exception) 194 | { 195 | $response = json_decode($exception->getResponse()->getBody()->getContents(), true); 196 | return $this->getResponseFromArray($response); 197 | } 198 | } 199 | -------------------------------------------------------------------------------- /src/Response/AnnotateImageResponse.php: -------------------------------------------------------------------------------- 1 | faceAnnotations; 79 | } 80 | 81 | /** 82 | * @param \Vision\Annotation\FaceAnnotation[] $faceAnnotations 83 | */ 84 | public function setFaceAnnotations($faceAnnotations) 85 | { 86 | $this->faceAnnotations = $faceAnnotations; 87 | } 88 | 89 | /** 90 | * @return EntityAnnotation 91 | */ 92 | public function getLandmarkAnnotations() 93 | { 94 | return $this->landmarkAnnotations; 95 | } 96 | 97 | /** 98 | * @param EntityAnnotation $landmarkAnnotations 99 | */ 100 | public function setLandmarkAnnotations($landmarkAnnotations) 101 | { 102 | $this->landmarkAnnotations = $landmarkAnnotations; 103 | } 104 | 105 | /** 106 | * @return EntityAnnotation[] 107 | */ 108 | public function getLogoAnnotations() 109 | { 110 | return $this->logoAnnotations; 111 | } 112 | 113 | /** 114 | * @param EntityAnnotation[] $logoAnnotations 115 | */ 116 | public function setLogoAnnotations($logoAnnotations) 117 | { 118 | $this->logoAnnotations = $logoAnnotations; 119 | } 120 | 121 | /** 122 | * @return EntityAnnotation[] 123 | */ 124 | public function getLabelAnnotations() 125 | { 126 | return $this->labelAnnotations; 127 | } 128 | 129 | /** 130 | * @param EntityAnnotation[] $labelAnnotations 131 | */ 132 | public function setLabelAnnotations($labelAnnotations) 133 | { 134 | $this->labelAnnotations = $labelAnnotations; 135 | } 136 | 137 | /** 138 | * @return EntityAnnotation[] 139 | */ 140 | public function getTextAnnotations() 141 | { 142 | return $this->textAnnotations; 143 | } 144 | 145 | /** 146 | * @param EntityAnnotation[] $textAnnotations 147 | */ 148 | public function setTextAnnotations($textAnnotations) 149 | { 150 | $this->textAnnotations = $textAnnotations; 151 | } 152 | 153 | /** 154 | * @return TextAnnotation 155 | */ 156 | public function getFullTextAnnotation() 157 | { 158 | return $this->fullTextAnnotation; 159 | } 160 | 161 | /** 162 | * @param TextAnnotation $fullTextAnnotation 163 | */ 164 | public function setFullTextAnnotation($fullTextAnnotation) 165 | { 166 | $this->fullTextAnnotation = $fullTextAnnotation; 167 | } 168 | 169 | /** 170 | * @return SafeSearchAnnotation 171 | */ 172 | public function getSafeSearchAnnotation() 173 | { 174 | return $this->safeSearchAnnotation; 175 | } 176 | 177 | /** 178 | * @param SafeSearchAnnotation $safeSearchAnnotation 179 | */ 180 | public function setSafeSearchAnnotation($safeSearchAnnotation) 181 | { 182 | $this->safeSearchAnnotation = $safeSearchAnnotation; 183 | } 184 | 185 | /** 186 | * @return ImagePropertiesAnnotation 187 | */ 188 | public function getImagePropertiesAnnotation() 189 | { 190 | return $this->imagePropertiesAnnotation; 191 | } 192 | 193 | /** 194 | * @param ImagePropertiesAnnotation $imagePropertiesAnnotation 195 | */ 196 | public function setImagePropertiesAnnotation($imagePropertiesAnnotation) 197 | { 198 | $this->imagePropertiesAnnotation = $imagePropertiesAnnotation; 199 | } 200 | 201 | /** 202 | * @return WebDetection 203 | */ 204 | public function getWebDetection() 205 | { 206 | return $this->webDetection; 207 | } 208 | 209 | /** 210 | * @param WebDetection $webDetection 211 | */ 212 | public function setWebDetection($webDetection) 213 | { 214 | $this->webDetection = $webDetection; 215 | } 216 | 217 | /** 218 | * @return CropHintsAnnotation 219 | */ 220 | public function getCropHintsAnnotation() 221 | { 222 | return $this->cropHintsAnnotation; 223 | } 224 | 225 | /** 226 | * @param CropHintsAnnotation $cropHintsAnnotation 227 | */ 228 | public function setCropHintsAnnotation($cropHintsAnnotation) 229 | { 230 | $this->cropHintsAnnotation = $cropHintsAnnotation; 231 | } 232 | 233 | /** 234 | * @return Error 235 | */ 236 | public function getError() 237 | { 238 | return $this->error; 239 | } 240 | 241 | /** 242 | * @param Error $error 243 | */ 244 | public function setError($error) 245 | { 246 | $this->error = $error; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/Vision.php: -------------------------------------------------------------------------------- 1 | apiKey = $apiKey; 61 | $this->version = $version; 62 | $this->setFeatures($features); 63 | $this->setImageContext($imageContext); 64 | $this->httpClient = $httpClient ?: new Client; 65 | } 66 | 67 | /** 68 | * @param ImageInterface $image 69 | * @param string $responseType 70 | * @return string|AnnotateImageResponse 71 | */ 72 | public function request( 73 | ImageInterface $image, 74 | $responseType = self::RESPONSE_TYPE_OBJECT 75 | ) { 76 | $this->visionRequest = new VisionRequest($this->apiKey, $image, $this->features, $this->imageContext); 77 | $this->visionRequest->setVersion($this->version); 78 | $this->visionRequest->send($this->httpClient); 79 | 80 | return $this->getResponseForType($responseType); 81 | } 82 | 83 | /** 84 | * @param string $responseType 85 | * @return AnnotateImageResponse|string 86 | */ 87 | public function getResponseForType($responseType) 88 | { 89 | return $responseType === self::RESPONSE_TYPE_JSON 90 | ? $this->visionRequest->getRawResponse() 91 | : $this->visionRequest->getAnnotateImageResponse(); 92 | } 93 | 94 | /** 95 | * @return Feature[] 96 | */ 97 | public function getFeatures() 98 | { 99 | return $this->features; 100 | } 101 | 102 | /** 103 | * @param Feature[] $features 104 | */ 105 | public function setFeatures($features) 106 | { 107 | $this->features = $features; 108 | } 109 | 110 | /** 111 | * @param Feature $feature 112 | */ 113 | public function addFeature($feature) 114 | { 115 | $this->features[] = $feature; 116 | } 117 | 118 | /** 119 | * @return ImageContext 120 | */ 121 | public function getImageContext() 122 | { 123 | return $this->imageContext; 124 | } 125 | 126 | /** 127 | * @param ImageContext $imageContext 128 | */ 129 | public function setImageContext($imageContext) 130 | { 131 | $this->imageContext = $imageContext ?: new ImageContext; 132 | } 133 | 134 | /** 135 | * @return Client 136 | */ 137 | public function getHttpClient() 138 | { 139 | return $this->httpClient; 140 | } 141 | 142 | /** 143 | * @param Client $httpClient 144 | */ 145 | public function setHttpClient($httpClient) 146 | { 147 | $this->httpClient = $httpClient; 148 | } 149 | 150 | /** 151 | * @deprecated 152 | * 153 | * @param Image $image 154 | * @param string $responseType 155 | * @return string|AnnotateImageResponse 156 | */ 157 | public function getRequest(Image $image, $responseType = self::RESPONSE_TYPE_OBJECT) 158 | { 159 | return $this->request($image, $responseType); 160 | } 161 | } 162 | -------------------------------------------------------------------------------- /tests/FeatureTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray(), new AnnotateImageResponse); 18 | 19 | $this->assertEquals($this->getObject(), $object); 20 | } 21 | 22 | public function testExtractsObject() 23 | { 24 | $strategy = new AnnotateImageHydrator(); 25 | $array = $strategy->extract($this->getObject()); 26 | 27 | $this->assertEquals($this->getArray(), $array); 28 | } 29 | 30 | /** 31 | * @return AnnotateImageResponse 32 | */ 33 | protected function getObject() 34 | { 35 | $boundingPoly = new BoundingPoly; 36 | $boundingPoly->addVertex(new Vertex(129, 203)); 37 | $boundingPoly->addVertex(new Vertex(458, 203)); 38 | 39 | $entityAnnotation = new EntityAnnotation; 40 | $entityAnnotation->setMid('/m/0b34hf'); 41 | $entityAnnotation->setDescription('Google'); 42 | $entityAnnotation->setScore(0.31551266); 43 | $entityAnnotation->setBoundingPoly($boundingPoly); 44 | 45 | $safeSearchAnnotation = new SafeSearchAnnotation; 46 | $safeSearchAnnotation->setAdult('VERY_UNLIKELY'); 47 | $safeSearchAnnotation->setSpoof('VERY_UNLIKELY'); 48 | $safeSearchAnnotation->setMedical('LIKELY'); 49 | $safeSearchAnnotation->setViolence('UNLIKELY'); 50 | $safeSearchAnnotation->setRacy('VERY_UNLIKELY'); 51 | 52 | $annotateImageResponse = new AnnotateImageResponse; 53 | $annotateImageResponse->setLogoAnnotations([$entityAnnotation]); 54 | $annotateImageResponse->setSafeSearchAnnotation($safeSearchAnnotation); 55 | 56 | return $annotateImageResponse; 57 | } 58 | 59 | /** 60 | * @return array 61 | */ 62 | protected function getArray() 63 | { 64 | return [ 65 | 'logoAnnotations' => [ 66 | [ 67 | 'mid' => '/m/0b34hf', 68 | 'description' => 'Google', 69 | 'score' => 0.31551266, 70 | 'boundingPoly' => [ 71 | 'vertices' => [ 72 | [ 73 | 'x' => 129, 74 | 'y' => 203, 75 | ], 76 | [ 77 | 'x' => 458, 78 | 'y' => 203, 79 | ], 80 | ], 81 | ], 82 | 'properties' => [], 83 | 'locations' => [] 84 | ], 85 | ], 86 | 'safeSearchAnnotation' => [ 87 | 'adult' => 'VERY_UNLIKELY', 88 | 'spoof' => 'VERY_UNLIKELY', 89 | 'medical' => 'LIKELY', 90 | 'violence' => 'UNLIKELY', 91 | 'racy' => 'VERY_UNLIKELY', 92 | ], 93 | ]; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/BoundingPolyStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 15 | 16 | $this->assertEquals($this->getObject(), $object); 17 | } 18 | 19 | public function testExtractsObject() 20 | { 21 | $strategy = new BoundingPolyStrategy(); 22 | $array = $strategy->extract($this->getObject()); 23 | 24 | $this->assertEquals($this->getArray(), $array); 25 | } 26 | 27 | /** 28 | * @return array 29 | */ 30 | protected function getArray() 31 | { 32 | return [ 33 | 'vertices' => [ 34 | [ 35 | 'x' => 12, 36 | 'y' => 6 37 | ], 38 | [ 39 | 'x' => 4, 40 | 'y' => 3 41 | ] 42 | ] 43 | ]; 44 | } 45 | 46 | /** 47 | * @return BoundingPoly 48 | */ 49 | protected function getObject() 50 | { 51 | $object = new BoundingPoly; 52 | $object->addVertex(new Vertex(12, 6)); 53 | $object->addVertex(new Vertex(4, 3)); 54 | 55 | return $object; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/CropHintStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 16 | 17 | $this->assertEquals($this->getObjects(), $objects); 18 | } 19 | 20 | public function testExtractsObject() 21 | { 22 | $strategy = new CropHintStrategy(); 23 | $array = $strategy->extract($this->getObjects()); 24 | 25 | $this->assertEquals($this->getArray(), $array); 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | protected function getArray() 32 | { 33 | return [ 34 | [ 35 | 'boundingPoly' => [ 36 | 'vertices' => [ 37 | [], 38 | ['x' => 1100], 39 | ['x' => 1100, 'y' => 1467], 40 | ['y' => 1467] 41 | ], 42 | ], 43 | 'confidence' => 0.79999995, 44 | 'importanceFraction' => 1 45 | ] 46 | ]; 47 | } 48 | 49 | /** 50 | * @return CropHint[] 51 | */ 52 | protected function getObjects() 53 | { 54 | $boundingPoly = new BoundingPoly(); 55 | $boundingPoly->addVertex(new Vertex()); 56 | $boundingPoly->addVertex(new Vertex(1100)); 57 | $boundingPoly->addVertex(new Vertex(1100, 1467)); 58 | $boundingPoly->addVertex(new Vertex(null, 1467)); 59 | 60 | return [ 61 | new CropHint($boundingPoly, 0.79999995, 1), 62 | ]; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/CropHintsParamsStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new CropHintsParamsStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | 'aspectRatios' => [1.21, 0.78] 33 | ]; 34 | } 35 | 36 | /** 37 | * @return CropHintsParams 38 | */ 39 | protected function getObjects() 40 | { 41 | return new CropHintsParams([1.21, 0.78]); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/DetectedBreakStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObject(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new DetectedBreakStrategy(); 21 | $array = $strategy->extract($this->getObject()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | 'type' => 'SPACE', 33 | ]; 34 | } 35 | 36 | /** 37 | * @return DetectedBreak 38 | */ 39 | protected function getObject() 40 | { 41 | return new DetectedBreak('SPACE', false); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/DetectedLanguagesStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new DetectedLanguagesStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | [ 33 | 'languageCode' => 'en', 34 | ], 35 | [ 36 | 'languageCode' => 'nl', 37 | 'confidence' => 0.5, 38 | ], 39 | ]; 40 | } 41 | 42 | /** 43 | * @return DetectedLanguage[] 44 | */ 45 | protected function getObjects() 46 | { 47 | return [ 48 | new DetectedLanguage('en'), 49 | new DetectedLanguage('nl', 0.5), 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/DominantColorsStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 15 | 16 | $this->assertEquals($this->getObjects(), $objects); 17 | } 18 | 19 | public function testExtractsObject() 20 | { 21 | $strategy = new DominantColorsStrategy(); 22 | $array = $strategy->extract($this->getObjects()); 23 | 24 | $this->assertEquals($this->getArray(), $array); 25 | } 26 | 27 | /** 28 | * @return array 29 | */ 30 | protected function getArray() 31 | { 32 | return [ 33 | 'colors' => [ 34 | [ 35 | 'color' => [ 36 | 'red' => 12, 37 | 'green' => 34, 38 | 'blue' => 56, 39 | ], 40 | 'score' => 78, 41 | 'pixelFraction' => 90, 42 | ], 43 | [ 44 | 'color' => [ 45 | 'red' => 9, 46 | 'green' => 98, 47 | 'blue' => 76, 48 | ], 49 | 'score' => 54, 50 | 'pixelFraction' => 32, 51 | ], 52 | ] 53 | ]; 54 | } 55 | 56 | /** 57 | * @return DominantColor[] 58 | */ 59 | protected function getObjects() 60 | { 61 | $objectA = new DominantColor; 62 | $objectA->setColor(new Color(12, 34, 56)); 63 | $objectA->setScore(78); 64 | $objectA->setPixelFraction(90); 65 | 66 | $objectB = new DominantColor; 67 | $objectB->setColor(new Color(9, 98, 76)); 68 | $objectB->setScore(54); 69 | $objectB->setPixelFraction(32); 70 | 71 | return [$objectA, $objectB]; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/LandmarkStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 15 | 16 | $this->assertEquals($this->getObjects(), $objects); 17 | } 18 | 19 | public function testExtractsObject() 20 | { 21 | $strategy = new LandmarkStrategy(); 22 | $array = $strategy->extract($this->getObjects()); 23 | 24 | $this->assertEquals($this->getArray(), $array); 25 | } 26 | 27 | /** 28 | * @return array 29 | */ 30 | protected function getArray() 31 | { 32 | return [ 33 | [ 34 | 'type' => 'a', 35 | 'position' => [ 36 | 'x' => 12, 37 | 'y' => 34, 38 | 'z' => 56, 39 | ], 40 | ], 41 | [ 42 | 'type' => 'b', 43 | 'position' => [ 44 | 'x' => 33, 45 | 'y' => 44, 46 | 'z' => 55, 47 | ], 48 | ], 49 | ]; 50 | } 51 | 52 | /** 53 | * @return Landmark[] 54 | */ 55 | protected function getObjects() 56 | { 57 | $landmarkA = new Landmark(); 58 | $landmarkA->setType('a'); 59 | $landmarkA->setPosition( 60 | new Position(12, 34, 56) 61 | ); 62 | 63 | $landmarkB = new Landmark(); 64 | $landmarkB->setType('b'); 65 | $landmarkB->setPosition( 66 | new Position(33, 44, 55) 67 | ); 68 | 69 | return [$landmarkA, $landmarkB]; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/LatLongRectStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 15 | 16 | $this->assertEquals($this->getObjects(), $object); 17 | } 18 | 19 | public function testExtractsObject() 20 | { 21 | $strategy = new LatLongRectStrategy(); 22 | $array = $strategy->extract($this->getObjects()); 23 | 24 | $this->assertEquals($this->getArray(), $array); 25 | } 26 | 27 | /** 28 | * @return array 29 | */ 30 | protected function getArray() 31 | { 32 | return [ 33 | 'minLatLng' => [ 34 | 'latitude' => 5.3814712, 35 | 'longitude' => 51.4455368 36 | ], 37 | 'maxLatLng' => [ 38 | 'latitude' => 51.5285582, 39 | 'longitude' => -0.2416796 40 | ] 41 | ]; 42 | } 43 | 44 | /** 45 | * @return LatLongRect 46 | */ 47 | protected function getObjects() 48 | { 49 | return new LatLongRect( 50 | new LatLng(5.3814712, 51.4455368), 51 | new LatLng(51.5285582, -0.2416796) 52 | ); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/LocationStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 15 | 16 | $this->assertEquals($this->getObjects(), $objects); 17 | } 18 | 19 | public function testExtractsObject() 20 | { 21 | $strategy = new LocationStrategy(); 22 | $array = $strategy->extract($this->getObjects()); 23 | 24 | $this->assertEquals($this->getArray(), $array); 25 | } 26 | 27 | /** 28 | * @return array 29 | */ 30 | protected function getArray() 31 | { 32 | return [ 33 | [ 34 | 'latLng' => [ 35 | 'latitude' => 12.34, 36 | 'longitude' => 56.78, 37 | ] 38 | ], 39 | [ 40 | 'latLng' => [ 41 | 'latitude' => 11.22, 42 | 'longitude' => 33.44, 43 | ] 44 | ], 45 | ]; 46 | } 47 | 48 | /** 49 | * @return Location[] 50 | */ 51 | protected function getObjects() 52 | { 53 | return [ 54 | new Location(new LatLng(12.34, 56.78)), 55 | new Location(new LatLng(11.22, 33.44)) 56 | ]; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/PropertyStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $objects); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new PropertyStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | [ 33 | 'name' => 'foo', 34 | 'value' => 'bar' 35 | ], 36 | [ 37 | 'name' => 'hello', 38 | 'value' => 'world' 39 | ] 40 | ]; 41 | } 42 | 43 | /** 44 | * @return Property[] 45 | */ 46 | protected function getObjects() 47 | { 48 | return [ 49 | new Property('foo', 'bar'), 50 | new Property('hello', 'world') 51 | ]; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/WebDetectionParamsStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 16 | 17 | $this->assertEquals($this->getObjects(), $object); 18 | } 19 | 20 | public function testExtractsObject() 21 | { 22 | $strategy = new WebDetectionParamsStrategy(); 23 | $array = $strategy->extract($this->getObjects()); 24 | 25 | $this->assertEquals($this->getArray(), $array); 26 | } 27 | 28 | /** 29 | * @return array 30 | */ 31 | protected function getArray() 32 | { 33 | return [ 34 | 'includeGeoResults' => true 35 | ]; 36 | } 37 | 38 | /** 39 | * @return WebDetectionParams 40 | */ 41 | protected function getObjects() 42 | { 43 | return new WebDetectionParams(true); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/WebEntitiesStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new WebEntitiesStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | [ 33 | 'entityId' => '/g/11cnx_67bx', 34 | 'description' => 'Eiffel Tower', 35 | 'score' => 0.76444 36 | ], 37 | [ 38 | 'entityId' => '/m/01fdzj', 39 | 'description' => 'Tower' 40 | ], 41 | ]; 42 | } 43 | 44 | /** 45 | * @return WebEntity[] 46 | */ 47 | protected function getObjects() 48 | { 49 | return [ 50 | new WebEntity('/g/11cnx_67bx', 'Eiffel Tower', 0.76444), 51 | new WebEntity('/m/01fdzj', 'Tower') 52 | ]; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/WebImagesStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new WebImagesStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | [ 33 | 'url' => 'https://i2.wp.com/thetradingtravelers.com/wp-content/uploads/2014/07/eiffel-tower-day.jpg?fit=400%2C600', 34 | ], 35 | [ 36 | 'url' => 'https://hh2983bckk73apigx3cu5b3t23-wpengine.netdna-ssl.com/wp-content/uploads/2015/10/Eiffel-Tower-1.jpg', 37 | 'score' => 0.12345 38 | ] 39 | ]; 40 | } 41 | 42 | /** 43 | * @return WebImage[] 44 | */ 45 | protected function getObjects() 46 | { 47 | return [ 48 | new WebImage('https://i2.wp.com/thetradingtravelers.com/wp-content/uploads/2014/07/eiffel-tower-day.jpg?fit=400%2C600'), 49 | new WebImage('https://hh2983bckk73apigx3cu5b3t23-wpengine.netdna-ssl.com/wp-content/uploads/2015/10/Eiffel-Tower-1.jpg', 0.12345) 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/Hydrator/Strategy/WebPagesStrategyTest.php: -------------------------------------------------------------------------------- 1 | hydrate($this->getArray()); 14 | 15 | $this->assertEquals($this->getObjects(), $object); 16 | } 17 | 18 | public function testExtractsObject() 19 | { 20 | $strategy = new WebPagesStrategy(); 21 | $array = $strategy->extract($this->getObjects()); 22 | 23 | $this->assertEquals($this->getArray(), $array); 24 | } 25 | 26 | /** 27 | * @return array 28 | */ 29 | protected function getArray() 30 | { 31 | return [ 32 | [ 33 | 'url' => 'https://www.viator.com/Paris-attractions/Eiffel-Tower/d479-a89', 34 | ], 35 | [ 36 | 'url' => 'https://www.viator.com/Paris-attractions/Eiffel-Tower/d479-a89', 37 | 'score' => 0.12345 38 | ] 39 | ]; 40 | } 41 | 42 | /** 43 | * @return WebPage[] 44 | */ 45 | protected function getObjects() 46 | { 47 | return [ 48 | new WebPage('https://www.viator.com/Paris-attractions/Eiffel-Tower/d479-a89'), 49 | new WebPage('https://www.viator.com/Paris-attractions/Eiffel-Tower/d479-a89', 0.12345) 50 | ]; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /tests/ImageTest.php: -------------------------------------------------------------------------------- 1 | setImage('IR&^FKUI^&'); 17 | } 18 | 19 | /** 20 | * @expectedException \Vision\Exception\ImageException 21 | * @expectedExceptionMessage Could not load the given image 22 | */ 23 | public function testExceptionOnInvalidImage() 24 | { 25 | new Image('path/to/notfound'); 26 | } 27 | 28 | public function testImageSetOnLoad() 29 | { 30 | $image = new Image(__dir__ . '/Resources/testimage.jpg'); 31 | $this->assertNotNull($image); 32 | $this->assertEquals($this->getTestImageBase(), $image->getImage()); 33 | } 34 | 35 | /** 36 | * @return string 37 | */ 38 | protected function getTestImageBase() 39 | { 40 | return "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAJAAkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A/VLHHWkx71meJ/EVt4U8O6lrN3HNNb2MDzvFbpukcKM7UBIyx6DJHJ6ivl3UP+Chui2V28MvgTXtNCnGNZH2V/xCq4H4E1LkluB9a/jR+NfMfh39uvw3rRl+0aWtiFGV/wBLeUv7DEPB+uK9F+GP7SnhX4o+I20Gyju7HVfJaeOK68srOi43FCjseMj7wWndAtdj1j8aKMiimBheOvD8vivwdrGkW8iQz3ls8UbyZ2hiOM45xnHTP0NfHvi2e9+H1vc23iPTNS0hUGPPntJGtm/3Z0DRH1xuz6gV9vcY6UVLVyXG5+T2teLNE1wm0sbq2v7l2Pl2tmvnysfZUBJP0r379hz4DeLPD/xHvvHOt6Bc+HdJ+wS2lrDqcRt7qaR3TJEDAOigI2S4UnK4BGSPuT86Tj0pKCTuNXSs2Lj2opMD0oqxi9qCKKKAAj3ox05oooAAMjrRRRQB/9k="; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/Request/Image/Base64ImageTest.php: -------------------------------------------------------------------------------- 1 | setValue('IR&^FKUI^&'); 17 | } 18 | 19 | public function testNoExceptionOnValidEncoding() 20 | { 21 | $image = new Base64Image(); 22 | $image->setValue($this->getTestImageBase()); 23 | } 24 | 25 | /** 26 | * @return string 27 | */ 28 | protected function getTestImageBase() 29 | { 30 | return "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAJAAkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A/VLHHWkx71meJ/EVt4U8O6lrN3HNNb2MDzvFbpukcKM7UBIyx6DJHJ6ivl3UP+Chui2V28MvgTXtNCnGNZH2V/xCq4H4E1LkluB9a/jR+NfMfh39uvw3rRl+0aWtiFGV/wBLeUv7DEPB+uK9F+GP7SnhX4o+I20Gyju7HVfJaeOK68srOi43FCjseMj7wWndAtdj1j8aKMiimBheOvD8vivwdrGkW8iQz3ls8UbyZ2hiOM45xnHTP0NfHvi2e9+H1vc23iPTNS0hUGPPntJGtm/3Z0DRH1xuz6gV9vcY6UVLVyXG5+T2teLNE1wm0sbq2v7l2Pl2tmvnysfZUBJP0r379hz4DeLPD/xHvvHOt6Bc+HdJ+wS2lrDqcRt7qaR3TJEDAOigI2S4UnK4BGSPuT86Tj0pKCTuNXSs2Lj2opMD0oqxi9qCKKKAAj3ox05oooAAMjrRRRQB/9k="; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/Request/Image/BinaryImageTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($this->getTestImageBase(), $image->getValue()); 13 | } 14 | 15 | /** 16 | * @return string 17 | */ 18 | protected function getTestImageBase() 19 | { 20 | return "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAJAAkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A/VLHHWkx71meJ/EVt4U8O6lrN3HNNb2MDzvFbpukcKM7UBIyx6DJHJ6ivl3UP+Chui2V28MvgTXtNCnGNZH2V/xCq4H4E1LkluB9a/jR+NfMfh39uvw3rRl+0aWtiFGV/wBLeUv7DEPB+uK9F+GP7SnhX4o+I20Gyju7HVfJaeOK68srOi43FCjseMj7wWndAtdj1j8aKMiimBheOvD8vivwdrGkW8iQz3ls8UbyZ2hiOM45xnHTP0NfHvi2e9+H1vc23iPTNS0hUGPPntJGtm/3Z0DRH1xuz6gV9vcY6UVLVyXG5+T2teLNE1wm0sbq2v7l2Pl2tmvnysfZUBJP0r379hz4DeLPD/xHvvHOt6Bc+HdJ+wS2lrDqcRt7qaR3TJEDAOigI2S4UnK4BGSPuT86Tj0pKCTuNXSs2Lj2opMD0oqxi9qCKKKAAj3ox05oooAAMjrRRRQB/9k="; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /tests/Request/Image/GoogleCloudImageTest.php: -------------------------------------------------------------------------------- 1 | setObjectName('object.jpg'); 13 | 14 | $value = $googleCloudImage->getValue(); 15 | $this->assertArrayHasKey('imageUri',$value); 16 | $this->assertEquals('gs://bucket-name/object.jpg', $value['imageUri']); 17 | } 18 | 19 | public function testGCPrefixIsPrepended() 20 | { 21 | $googleCloudImage = new GoogleCloudImage('bucket-name'); 22 | $googleCloudImage->setObjectName('object.jpg'); 23 | 24 | $value = $googleCloudImage->getValue(); 25 | $this->assertArrayHasKey('imageUri',$value); 26 | $this->assertEquals('gs://bucket-name/object.jpg', $value['imageUri']); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/Request/Image/LocalImageTest.php: -------------------------------------------------------------------------------- 1 | assertEquals($this->getTestImageBase(), $image->getValue()); 22 | } 23 | 24 | /** 25 | * @return string 26 | */ 27 | protected function getTestImageBase() 28 | { 29 | return "/9j/4AAQSkZJRgABAQEAYABgAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gOTAK/9sAQwADAgIDAgIDAwMDBAMDBAUIBQUEBAUKBwcGCAwKDAwLCgsLDQ4SEA0OEQ4LCxAWEBETFBUVFQwPFxgWFBgSFBUU/9sAQwEDBAQFBAUJBQUJFA0LDRQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQU/8AAEQgAJAAkAwEiAAIRAQMRAf/EAB8AAAEFAQEBAQEBAAAAAAAAAAABAgMEBQYHCAkKC//EALUQAAIBAwMCBAMFBQQEAAABfQECAwAEEQUSITFBBhNRYQcicRQygZGhCCNCscEVUtHwJDNicoIJChYXGBkaJSYnKCkqNDU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6g4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2drh4uPk5ebn6Onq8fLz9PX29/j5+v/EAB8BAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKC//EALURAAIBAgQEAwQHBQQEAAECdwABAgMRBAUhMQYSQVEHYXETIjKBCBRCkaGxwQkjM1LwFWJy0QoWJDThJfEXGBkaJicoKSo1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoKDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uLj5OXm5+jp6vLz9PX29/j5+v/aAAwDAQACEQMRAD8A/VLHHWkx71meJ/EVt4U8O6lrN3HNNb2MDzvFbpukcKM7UBIyx6DJHJ6ivl3UP+Chui2V28MvgTXtNCnGNZH2V/xCq4H4E1LkluB9a/jR+NfMfh39uvw3rRl+0aWtiFGV/wBLeUv7DEPB+uK9F+GP7SnhX4o+I20Gyju7HVfJaeOK68srOi43FCjseMj7wWndAtdj1j8aKMiimBheOvD8vivwdrGkW8iQz3ls8UbyZ2hiOM45xnHTP0NfHvi2e9+H1vc23iPTNS0hUGPPntJGtm/3Z0DRH1xuz6gV9vcY6UVLVyXG5+T2teLNE1wm0sbq2v7l2Pl2tmvnysfZUBJP0r379hz4DeLPD/xHvvHOt6Bc+HdJ+wS2lrDqcRt7qaR3TJEDAOigI2S4UnK4BGSPuT86Tj0pKCTuNXSs2Lj2opMD0oqxi9qCKKKAAj3ox05oooAAMjrRRRQB/9k="; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Request/Image/RemoteImageTest.php: -------------------------------------------------------------------------------- 1 | getValue(); 14 | $this->assertArrayHasKey('imageUri',$value); 15 | $this->assertEquals('test', $value['imageUri']); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tests/Request/VisionRequestTest.php: -------------------------------------------------------------------------------- 1 | image = new Base64Image(); 34 | $this->image->setValue('dGVzdA=='); 35 | 36 | $this->features = [ 37 | new \Vision\Feature(\Vision\Feature::LANDMARK_DETECTION, 1), 38 | new \Vision\Feature(\Vision\Feature::LABEL_DETECTION, 1), 39 | ]; 40 | } 41 | 42 | public function testPermissionsInjectedInPayload() 43 | { 44 | $request = $this->getVisionRequest(); 45 | 46 | $class = new \ReflectionClass($request); 47 | $method = $class->getMethod('getPayload'); 48 | $method->setAccessible(true); 49 | $payload = $method->invokeArgs($request, []); 50 | 51 | $this->assertEquals($this->getTestPayload(), $payload); 52 | } 53 | 54 | public function testReturnsClientException() 55 | { 56 | $request = $this->getVisionRequest(); 57 | 58 | $class = new \ReflectionClass($request); 59 | $property = $class->getProperty('clientException'); 60 | $property->setAccessible(true); 61 | $property->setValue( 62 | $request, 63 | new ClientException('exception message', 64 | new Request('GET', '/'), 65 | new Response(200,[],json_encode(["error" => ["code" => "test"]])) 66 | ) 67 | ); 68 | 69 | $this->assertEquals($request->getAnnotateImageResponse()->getError()->getCode(), 'test'); 70 | } 71 | 72 | public function testReturnsAnnotateImageResponse() 73 | { 74 | $request = $this->getVisionRequest(); 75 | 76 | $class = new \ReflectionClass($request); 77 | $property = $class->getProperty('rawResponse'); 78 | $property->setAccessible(true); 79 | $property->setValue($request, json_encode(["responses" => [[]]])); 80 | 81 | $this->assertTrue(get_class($request->getAnnotateImageResponse()) === AnnotateImageResponse::class); 82 | } 83 | 84 | public function testReturnsRawJson() 85 | { 86 | $json = '{"some_json":{}}'; 87 | 88 | $request = $this->getVisionRequest(); 89 | $class = new \ReflectionClass($request); 90 | $property = $class->getProperty('rawResponse'); 91 | $property->setAccessible(true); 92 | $property->setValue($request, $json); 93 | 94 | $this->assertEquals($request->getRawResponse(), $json); 95 | } 96 | 97 | public function testHydratesImageContext() 98 | { 99 | $request = $this->getVisionRequest(); 100 | $class = new \ReflectionClass($request); 101 | $method = $class->getMethod('extractImageContext'); 102 | $method->setAccessible(true); 103 | 104 | $payload = $method->invokeArgs($request, []); 105 | $imageContextTestPayload = $this->getTestPayload()['requests'][0]['imageContext']; 106 | 107 | $this->assertEquals($payload, $imageContextTestPayload); 108 | } 109 | 110 | /** 111 | * @return VisionRequest 112 | */ 113 | protected function getVisionRequest() 114 | { 115 | $imageContext = new ImageContext(); 116 | $imageContext->setLanguageHints(['lookbehind']); 117 | $imageContext->setCropHintsParams(new CropHintsParams([1.27])); 118 | $imageContext->setLatLongRect(new LatLongRect( 119 | new LatLng(5.3814712, 51.4455368), 120 | new LatLng(51.5285582, -0.2416796) 121 | )); 122 | 123 | return new VisionRequest('abc-123', $this->image, $this->features, $imageContext); 124 | } 125 | 126 | /** 127 | * @return array 128 | */ 129 | protected function getTestPayload() 130 | { 131 | return [ 132 | 'requests' => [ 133 | [ 134 | 'image' => ['content' => 'dGVzdA=='], 135 | 'features' => [ 136 | ['type' => 'LANDMARK_DETECTION', 'maxResults' => 1], 137 | ['type' => 'LABEL_DETECTION', 'maxResults' => 1] 138 | ], 139 | 'imageContext' => [ 140 | 'latLongRect' => [ 141 | 'minLatLng' => ['latitude' => 5.3814712, 'longitude' => 51.4455368], 142 | 'maxLatLng' => ['latitude' => 51.5285582, 'longitude' => -0.2416796] 143 | ], 144 | 'languageHints' => ['lookbehind'], 145 | 'cropHintsParams' => ['aspectRatios' => [1.27]] 146 | ] 147 | ], 148 | ], 149 | ]; 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /tests/Resources/testimage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jordikroon/Php-Google-Vision-Api/59077c178424d62c439829ece4aab26bebc303d8/tests/Resources/testimage.jpg -------------------------------------------------------------------------------- /tests/bootstrap.php: -------------------------------------------------------------------------------- 1 |