PHP code example of cloudinary / cloudinary_php

1. Go to this page and download the library: Download cloudinary/cloudinary_php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cloudinary / cloudinary_php example snippets




loudinary\Cloudinary;
use Cloudinary\Transformation\Delivery;
use Cloudinary\Transformation\Format;
use Cloudinary\Transformation\Gravity;
use Cloudinary\Transformation\Quality;
use Cloudinary\Transformation\Resize;

try {
    $cloudinary = new Cloudinary();

    // Upload a remote image (a local file path works the same way).
    $result = $cloudinary->uploadApi()->upload(
        'https://res.cloudinary.com/demo/image/upload/sample.jpg',
        ['public_id' => 'quickstart-sample']
    );

    echo 'Uploaded: ', $result['public_id'], PHP_EOL;

    // Build a 400x400 auto-cropped URL with automatic format and quality.
    $url = $cloudinary->image($result['public_id'])
        ->resize(Resize::fill(400, 400)->gravity(Gravity::auto()))
        ->delivery(Delivery::format(Format::auto()))
        ->delivery(Delivery::quality(Quality::auto()));

    echo 'Optimized URL: ', $url, PHP_EOL;
} catch (Throwable $e) {
    fwrite(STDERR, 'Quick start failed: ' . $e->getMessage() . PHP_EOL);
    fwrite(STDERR, 'Check that CLOUDINARY_URL is set (Console > Settings > API Keys).' . PHP_EOL);
    exit(1);
}
bash
composer