Cloudinary PHP SDK
This package is auto-updated.
Last update: 2021-08-26 06:09:01 UTC
Cloudinary is a cloud service that offers a solution to a web application's entire image management pipeline.
Easily upload images to the cloud. Automatically perform smart image resizing, cropping and conversion without installing any complex software. Integrate Facebook or Twitter profile image extraction in a snap, in any dimension and style to match your website's graphics requirements. Images are seamlessly delivered through a fast CDN, and much much more.
Cloudinary offers comprehensive APIs and administration capabilities and is easy to integrate with any web application, existing or new.
Cloudinary provides URL and HTTP based APIs that can be easily integrated with any Web development framework.
For PHP, Cloudinary provides an extension for simplifying the integration even further.
Take a look at our Getting started guide for PHP.
You can install through composer with:
composer require "cloudinary/cloudinary_php:^2"
Or download cloudinary_php from here
Note: cloudinary_php require PHP 5.6
See the Cloudinary PHP SDK Migration guide for more information on migrating to this version of the PHP SDK.
The previous (1.x) version of the SDK is located here.
Each request for building a URL of a remote cloud resource must have the
cloud_name parameter set. Each request to our
secure APIs (e.g., image uploads, eager sprite generation) must have the
api_secret parameters set.
See API, URLs and access identifiers for more details.
Setting the cloud_name, api_key and api_secret parameters can be done either directly in each call to a Cloudinary method, by when initializing the Cloudinary object, or by using the CLOUDINARY_URL environment variable / system property.
The entry point of the library is the Cloudinary object.
$cloudinary = new Cloudinary();
Here's an example of setting the configuration parameters programatically:
$cloudinary = new Cloudinary( [ 'cloud' => [ 'cloud_name' => 'n07t21i7', 'api_key' => '123456789012345', 'api_secret' => 'abcdeghijklmnopqrstuvwxyz12', ], ] );
Another example of setting the configuration parameters by providing the CLOUDINARY_URL value to the constructor:
$cloudinary = new Cloudinary('cloudinary://123456789012345:abcdeghijklmnopqrstuvwxyz12@n07t21i7');
Any image uploaded to Cloudinary can be transformed and embedded using powerful view helper methods:
The following example generates the url for accessing an uploaded
sample image while transforming it to fill a 100x150
Another example, embedding a smaller version of an uploaded image while generating a 90x90 face detection based thumbnail:
Many other crop/resize modes can be found under
Resize:: static builder, use your IDE for auto-complete options.
Assuming you have your Cloudinary configuration parameters defined (
api_secret), uploading to
Cloudinary is very simple.
The following example uploads a local JPG to the cloud:
The uploaded image is assigned a randomly generated public ID. The image is immediately available for a download through a CDN:
$cloudinary->image('abcfrmo8zul1mafopawefg.jpg'); # http://res.cloudinary.com/demo/image/upload/abcfrmo8zul1mafopawefg.jpg
You can also specify your own public ID:
$cloudinary->uploadApi->upload('my_picture.jpg', ['public_id' => 'sample_remote']); $cloudinary->image('sample_remote.jpg'); # http://res.cloudinary.com/demo/image/upload/sample_remote.jpg
Returns an html image tag pointing to Cloudinary.
$cloudinary->imageTag('sample.png')->fill(100, 100); # <img src='http://res.cloudinary.com/cloud_name/image/upload/c_fill,h_100,w_100/sample.png'/>
Returns an HTML input field for direct image upload, to be used in conjunction with cloudinary_js package. It integrates jQuery-File-Upload widget and provides all the necessary parameters for a direct upload.
** See our documentation for plenty more options of uploading directly from the browser**.
Additional resources are available at:
- Interactive demo
- Knowledge Base
- Image transformations documentation
- Upload API documentation
You can open an issue through GitHub.
Impact the product, hear updates, test drive new features and more! Join here.
Run all tests:
Run only unit tests:
Run only integration tests:
All test commands also accept options such as
./vendor/bin/robo test:unit --coverage to generate test coverage reports
./vendor/bin/robo test:unit --dox to output an agile documentation from the tests.
Released under the MIT license.