cloudinary/media-editing

Cloudinary Media Editing PHP SDK

dev-main 2022-09-01 09:35 UTC

This package is auto-updated.

Last update: 2024-11-29 06:29:29 UTC


README

About

The Cloudinary Media Editing PHP SDK allows you to quickly and easily integrate your application with Cloudinary. Effortlessly edit and deliver your cloud's assets.

Additional documentation

This Readme provides basic installation and usage information. For the complete documentation, see the Media Editing SDK Guide.

Table of Contents

Key Features

Media Delivery API

Media Editing API

Version Support

Installation

composer require "cloudinary/media-editing"

Usage

Setup

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure with CLOUDINARY_URL
$config = Cloudinary\Configuration::getDefaultConfiguration()
    ->setCloudinaryUrl('cloudinary://key:secret@cloud_name');

Create Media Source

Example of how to add Media Storage, in this case a new media source:

$apiInstance = new Cloudinary\MediaDelivery\Api\MediaSourceApi(null, $deliveryConfig);

// Payload to create the Media Source
$mediaSourceCreatePayload = [
    "display_name" => "my_media_source",
    "source_type"  => "s3",
    "config"       => [
        "s3_bucket_name" => "my_bucket",
        "s3_bucket_folder" => "my_bucket_folder",
        "s3_access_key" => "123456789",
        "s3_secret_key" => "123456789",
        "s3_uri_template" => "s3://my_bucket/images/{{vars.signature}}/{{fwd_key}}",
    ],
];

try {
    $result = $apiInstance->createMediaSource($mediaSourceCreatePayload);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling MediaSourceApi->createMediaSource: ', $e->getMessage(), PHP_EOL;
}

Transform and Store

Example of how to transform and store an asset:

$apiInstance = new TransformAndStoreApi(null, $config);

$mediaSource = new MediaConnectorInstance();
$mediaSource->setId("11fcd4a3b294515067f1266c7e7f0422")->setFwdKey("sample");

$mediaTarget = new MediaConnectorInstance();
$mediaTarget->setId("33832c937c251b8566e4210736cec544")->setFwdKey("new_sample");

$transformRequest = new TransformRequest();

$transformation = new TransformationDescriptor();
$transformation->setCanonicalTransformation("c_scale,w_500");

$transformRequest->setInputType("media_source")
   ->setMediaSource($mediaSource)
   ->setMediaTarget($mediaTarget)
   ->setTransformationDescriptor($transformation);

try {
    $result = $apiInstance->transformAndStore($transformRequest);
    print_r($result);
} catch (\Exception $e) {
    echo 'Exception when calling TransformAndStoreApi->transformAndStore: ', $e->getMessage(), PHP_EOL;
}

Cache warmup

Example of how to perform a cache warmup:

$apiInstance = new Cloudinary\Api\CacheApi(null, $config);

$cacheWarmupRequestPayload = new \Cloudinary\MediaDelivery\Model\CacheWarmupRequestPayload(); // \Cloudinary\MediaDelivery\Model\CacheWarmupRequestPayload | Payload to warm up the cache

$cacheWarmupRequestPayload->setUrl("<your url>");
// $cacheWarmupRequestPayload->setUrl("https://<cloud_name>.media.cloudinary.net/image/upload/c_scale,w_500/sample");

try {
    $result = $apiInstance->warmup($cacheWarmupRequestPayload);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception when calling CacheApi->warmup: ', $e->getMessage(), PHP_EOL;
}

Get Help

About Cloudinary

Cloudinary is a powerful media API for websites and mobile apps alike, Cloudinary enables developers to efficiently manage, transform, optimize, and deliver images and videos through multiple CDNs. Ultimately, viewers enjoy responsive and personalized visual-media experiences—irrespective of the viewing device.

Additional Resources

License

Released under the MIT license See the LICENSE file for details.