PHP Classes
elePHPant
Icontem

File: README.md

Recommend this page to a friend!
  Classes of Emil Kilhage  >  PHP Pexels API  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Pexels API
Search for photos in the Pexels site using its API
Author: By
Last change: Update README.md
Date: 4 months ago
Size: 2,752 bytes
 

 

Contents

Class file image Download

Pexels API Client

Scrutinizer Code Quality Build Status Latest Stable Version Total Downloads License

Install

Install the Pexels API Client with Composer.

"require": {
    "glooby/pexels": "~0.1"
},

Usage

Create an instance of the Pexels API Client by passing in your API token as parameter.

$pexels = new \Glooby\Pexels\Client("xxxxx");

Perform a search, the response gets returned as an array

$response = $pexels->search('london');

Loop trough photos and display them

$photos = json_decode($pexels->search('london')->getBody())->photos;
foreach ($photos as $photo) {
 echo "<img src='{$photo->src->small}' width='{$photo->width}' heigth='{$photo->height}'>"
}

Example response

{
   "total_results":6,
   "page":1,
   "per_page":15,
   "photos":[  
      {  
         "id":57456,
         "width":4000,
         "height":3000,
         "url":"https://www.pexels.com/photo/brown-rocky-mountain-painting-57456/",
         "photographer":"Pixabay",
         "src":{  
            "original":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456.jpeg",
            "large":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-large.jpeg",
            "medium":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-medium.jpeg",
            "small":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-small.jpeg",
            "portrait":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-portrait.jpeg",
            "square":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-square.jpeg",
            "landscape":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-landscape.jpeg",
            "tiny":"https://static.pexels.com/photos/57456/torres-del-paine-mountains-granite-granite-rock-57456-tiny.jpeg"
         }
      }
   ]
}

www.glooby.com www.glooby.se