├── .gitignore ├── examples └── basic.php ├── composer.json ├── README.md ├── LICENSE.md ├── src └── FilePreviews │ ├── FilePreviewsClient.php │ └── FilePreviews.php └── composer.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/osx,composer 2 | 3 | ### OSX ### 4 | .DS_Store 5 | .AppleDouble 6 | .LSOverride 7 | 8 | # Icon must end with two \r 9 | Icon 10 | 11 | 12 | # Thumbnails 13 | ._* 14 | 15 | # Files that might appear in the root of a volume 16 | .DocumentRevisions-V100 17 | .fseventsd 18 | .Spotlight-V100 19 | .TemporaryItems 20 | .Trashes 21 | .VolumeIcon.icns 22 | 23 | # Directories potentially created on remote AFP share 24 | .AppleDB 25 | .AppleDesktop 26 | Network Trash Folder 27 | Temporary Items 28 | .apdisk 29 | 30 | 31 | ### Composer ### 32 | composer.phar 33 | vendor/ 34 | -------------------------------------------------------------------------------- /examples/basic.php: -------------------------------------------------------------------------------- 1 | [ 14 | 'width' => 250, 15 | 'height' => 250 16 | ], 17 | 'format' => 'jpg', 18 | 'pages' => '1', 19 | 'metadata' => ['exif', 'ocr', 'psd'], 20 | 'data' => ['foo' => 'bar'] 21 | ]; 22 | 23 | $response = $filepreviews->generate($url, $options); 24 | print_r($response->id); 25 | 26 | $response = $filepreviews->retrieve($response->id); 27 | print_r($response); 28 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "filepreviews/filepreviews", 3 | "description": "PHP client library for FilePreviews.io", 4 | "type": "library", 5 | "keywords": [ 6 | "file", 7 | "previews", 8 | "thumbnails", 9 | "metadata", 10 | "exif", 11 | "ocr" 12 | ], 13 | "homepage": "http://filepreviews.io", 14 | "license": "MIT", 15 | "authors": [ 16 | { 17 | "name": "José Padilla", 18 | "email": "jpadilla@blimp.io", 19 | "role": "Developer" 20 | } 21 | ], 22 | "support": { 23 | "email": "support@blimp.io", 24 | "source": "https://github.com/getblimp/filepreviews-php" 25 | }, 26 | "require": { 27 | "rmccue/requests": "~1.0" 28 | }, 29 | "autoload": { 30 | "psr-4": { 31 | "FilePreviews\\": "src/FilePreviews/" 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FilePreviews.io 2 | 3 | PHP client library for the [FilePreviews.io](http://filepreviews.io) service. Generate image previews and metadata from almost any kind of file. 4 | 5 | 6 | ## Installation 7 | 8 | ``` 9 | composer require filepreviews/filepreviews 10 | ``` 11 | 12 | ### Example code 13 | 14 | ```php 15 | $fp = new FilePreviews\FilePreviews([ 16 | 'api_key' => 'API_KEY_HERE', 17 | 'api_secret' => 'API_KEY_HERE' 18 | ]); 19 | 20 | $response = $fp->generate($url); 21 | print_r($response); 22 | 23 | $response = $fp->retrieve($response->id); 24 | print_r($response); 25 | ``` 26 | 27 | #### Options 28 | You can optionally send an options associative array. 29 | 30 | ```php 31 | $fp = new FilePreviews\FilePreviews([ 32 | 'api_key' => 'API_KEY_HERE', 33 | 'api_secret' => 'API_KEY_HERE' 34 | ]); 35 | 36 | $options = [ 37 | 'size' => [ 38 | 'width' => 250, 39 | 'height' => 250 40 | ], 41 | 'format' => 'jpg', 42 | 'pages' => '1', 43 | 'metadata' => ['exif', 'ocr', 'psd'], 44 | 'data' => ['foo' => 'bar'] 45 | ]; 46 | 47 | $response = $fp->generate($url, $options); 48 | print_r($response); 49 | ``` 50 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Blimp 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 | -------------------------------------------------------------------------------- /src/FilePreviews/FilePreviewsClient.php: -------------------------------------------------------------------------------- 1 | session = new \Requests_Session($config['api_url']); 11 | $this->session->auth = [ 12 | $config['api_key'], $config['api_secret'] 13 | ]; 14 | 15 | $client_ua = [ 16 | 'lang' => 'php', 17 | 'publisher' => 'filepreviews', 18 | 'bindings_version' => $config['version'], 19 | 'lang_version' => phpversion(), 20 | 'platform' => PHP_OS, 21 | 'uname' => php_uname(), 22 | ]; 23 | 24 | $this->session->headers = [ 25 | 'Accept' => 'application/json', 26 | 'Content-Type' => 'application/json', 27 | 'X-FilePreviews-Client-User-Agent' => json_encode($client_ua), 28 | 'User-Agent' => 'FilePreviews/v2 PhpBindings/' . $config['version'] 29 | ]; 30 | } 31 | 32 | public function get($path) 33 | { 34 | $request = $this->session->get($path); 35 | 36 | $request->throw_for_status(); 37 | 38 | return json_decode($request->body); 39 | } 40 | 41 | public function post($path, $data) 42 | { 43 | $request = $this->session->post($path, [], $data, []); 44 | 45 | $request->throw_for_status(); 46 | 47 | return json_decode($request->body); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/FilePreviews/FilePreviews.php: -------------------------------------------------------------------------------- 1 | getenv(static::API_KEY_ENV_NAME), 15 | 'api_secret' => getenv(static::API_SECRET_ENV_NAME), 16 | 'api_url' => static::API_URL, 17 | 'version' => static::VERSION 18 | ], $config); 19 | 20 | if (!$config['api_key']) { 21 | throw new \Exception('Required "api_key" key not supplied.'); 22 | } 23 | 24 | if (!$config['api_secret']) { 25 | throw new \Exception('Required "api_secret" key not supplied.'); 26 | } 27 | 28 | $this->client = new FilePreviewsClient($config); 29 | } 30 | 31 | public function generate($url, array $params = []) 32 | { 33 | $params = array_merge([ 34 | 'url' => $url, 35 | 'metadata' => [] 36 | ], $params); 37 | 38 | $metadata = array_unique($params['metadata']); 39 | 40 | if(empty($metadata)) 41 | { 42 | unset($params['metadata']); 43 | } 44 | 45 | if(isset($params['size'])) 46 | { 47 | $size = $params['size']; 48 | unset($params['size']); 49 | 50 | $geometry = ''; 51 | $size = array_merge([ 52 | 'height' => null, 53 | 'width' => null 54 | ], $size); 55 | 56 | if ($size['width'] !== null) 57 | { 58 | $geometry = "{$size['width']}"; 59 | } 60 | 61 | if ($size['height'] !== null) 62 | { 63 | $geometry = "{$geometry}x{$size['height']}"; 64 | } 65 | 66 | $params['sizes'] = [$geometry]; 67 | } 68 | 69 | return $this->client->post('previews/', json_encode($params)); 70 | } 71 | 72 | public function retrieve($preview_id) 73 | { 74 | return $this->client->get("previews/$preview_id/"); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /composer.lock: -------------------------------------------------------------------------------- 1 | { 2 | "_readme": [ 3 | "This file locks the dependencies of your project to a known state", 4 | "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", 5 | "This file is @generated automatically" 6 | ], 7 | "hash": "9e4f7467efb4d6bf4e037d11a4da9073", 8 | "packages": [ 9 | { 10 | "name": "rmccue/requests", 11 | "version": "v1.6.1", 12 | "source": { 13 | "type": "git", 14 | "url": "https://github.com/rmccue/Requests.git", 15 | "reference": "6aac485666c2955077d77b796bbdd25f0013a4ea" 16 | }, 17 | "dist": { 18 | "type": "zip", 19 | "url": "https://api.github.com/repos/rmccue/Requests/zipball/6aac485666c2955077d77b796bbdd25f0013a4ea", 20 | "reference": "6aac485666c2955077d77b796bbdd25f0013a4ea", 21 | "shasum": "" 22 | }, 23 | "require": { 24 | "php": ">=5.2" 25 | }, 26 | "require-dev": { 27 | "satooshi/php-coveralls": "dev-master" 28 | }, 29 | "type": "library", 30 | "autoload": { 31 | "psr-0": { 32 | "Requests": "library/" 33 | } 34 | }, 35 | "notification-url": "https://packagist.org/downloads/", 36 | "license": [ 37 | "ISC" 38 | ], 39 | "authors": [ 40 | { 41 | "name": "Ryan McCue", 42 | "homepage": "http://ryanmccue.info" 43 | } 44 | ], 45 | "description": "A HTTP library written in PHP, for human beings.", 46 | "homepage": "http://github.com/rmccue/Requests", 47 | "keywords": [ 48 | "curl", 49 | "fsockopen", 50 | "http", 51 | "idna", 52 | "ipv6", 53 | "iri", 54 | "sockets" 55 | ], 56 | "time": "2014-05-18 04:59:02" 57 | } 58 | ], 59 | "packages-dev": [], 60 | "aliases": [], 61 | "minimum-stability": "stable", 62 | "stability-flags": [], 63 | "prefer-stable": false, 64 | "prefer-lowest": false, 65 | "platform": [], 66 | "platform-dev": [] 67 | } 68 | --------------------------------------------------------------------------------