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
2020-12-20 (2 months ago) RSS 2.0 feedNot enough user ratingsTotal: 56 All time: 9,896 This week: 204Up
Version License PHP version Categories
pexels 1.0.3MIT/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.

Picture of Emil Kilhage
Name: Emil Kilhage <contact>
Classes: 3 packages by
Country: Sweden Sweden

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

$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

  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:56
This week:0
All time:9,896
This week:204Up

For more information send a message to info at phpclasses dot org.