PHP Classes
elePHPant
Icontem

PHP Pexels API: Search for photos in the Pexels site using its API

Recommend this page to a friend!
  Info   View files Documentation   View files View files (12)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2018-11-24 (17 days ago) RSS 2.0 feedNot enough user ratingsTotal: 48 This week: 1All time: 9,361 This week: 386Up
Version License PHP version Categories
pexels 1.0MIT/X Consortium ...5PHP 5, Graphics, Web services
Description Author

This class can search for photos in the Pexels site using its API.

It can send HTTP requests to the Pexels API Web server to perform searches for photos with given query keywords.

The class can limit the number of photos returned by search query page, as well specify the number of results page to retriev.

Name: Emil Kilhage <contact>
Classes: 3 packages by
Country: Sweden Sweden
Age: ???
All time rank: 421128 in Sweden Sweden
Week rank: 323 Up2 in Sweden Sweden Up

Details

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

$images = json_decode($pexels->search('london')->getBody())->images;
foreach ($images as $image) {
 echo "<img src='{$image->src->small}' width='{$image->width}' heigth='{$image->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

  Files folder image Files  
File Role Description
Files folder imagescript (3 files)
Files folder imagesrc (1 file)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file .travis.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file CONTRIBUTING.md Data Auxiliary data
Accessible without login Plain text file contributors.txt Data Contributors list
Accessible without login Plain text file LICENSE.md Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  script  
File Role Description
  Accessible without login Plain text file bootstrap Data Auxiliary data
  Accessible without login Plain text file setperm Data Auxiliary data
  Accessible without login Plain text file updatedeps Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file Client.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:48
This week:1
All time:9,361
This week:386Up