Front-End Development Adding Video to Your React Native App with react-native-video HTML Image Slider: Do It Yourself and 1-Step Image Gallery Widget How to Effectively Manage Digital Assets in a PHP Image Gallery Introducing Angular Image Editor: Your New Editing Too Mastering Javascript Image Annotation Mastering JavaScript Image Popup Python Video Player: 3 Free Options and a Quick Tutorial Image Recognition Machine Learning: Use Cases and Common Algorithms HTML/CSS: How to Center Images Vertically and Horizontally How to Create an Image Map Understand CSS Background Position with 4 Simple Examples Java for Image Processing: 4 Libraries You Should Know Python Video Processing: 6 Useful Libraries and a Quick Tutorial Blur Image CSS: Two Ways to Blur Images for Gorgeous Effects Designing a Video Flipping App for Android Build an App for Embedding Video Watermarks on Android Devices Change Image on Hover with HTML and CSS How to Align Images with CSS Full Page Background Image with CSS: Tutorial and 5 Automation Tips Using CSS to Scale Page Elements and a Better Way to Scale Your Images CSS Background Image: Quick Tutorial and 3 Automation Tips Featured Image: Best Practices to Feature Images on Your Website Image Gallery Websites: Tips and Tricks for a Stunning Image Gallery 6 Ways to Stretch a Background Image with CSS Auto Cropping for Images and Video: Features & Best Practices FLAC vs. WAV: 4 Key Differences and How to Choose Converting Audio to Video: A Practical Guide FLAC vs. AIFF: 5 Key Differences and How to Choose FLAC vs. MQA: 5 Key Differences and How to Choose Converting WAV Files To OGG The Ultimate Guide On Converting OGG Files To WAV Sound Choices: FLAC vs. MP3 AAC vs MP3 – The Future of Audio Files All about AIFF and how it compares to WAV and MP3 Integrating Cloudinary with Netlify Integrating Cloudinary with Svelte and SvelteKit Integrating Cloudinary with Nuxt Integrating Cloudinary with Gatsby File Upload as a Service: How It Works and 5 Leading Solutions Native Mobile App Development Creative Uses for CSS Inner Border and 3 Ways to Set a Border Integrating Cloudinary with Next.js Front-End Development: The Complete Guide

How to Effectively Manage Digital Assets in a PHP Image Gallery

php image gallery

A major challenge faced by web designers or developers is effectively storing and managing their media assets. Some image galleries are space-sensitive and lack basic functionality such as effective upload, transformation, and management.

Since tech professionals work with large and complex files, they must manage these media assets in reliable image galleries rather than conventional ones. But how can they assess extensive individual image galleries that are efficient, seamless, and well-optimized?

This article will explore Cloudinary’s PHP digital asset management, features, configuration, and basic functionalities such as upload, transformation, and management.

Transform and optimize your images and videos effortlessly with Cloudinary’s cloud-based solutions. Sign up for free today!

In this article:

php image gallery

The Cloudinary PHP SDK

The Cloudinary PHP SDK provides a powerful option for integrating Cloudinary’s Image and Video API and Digital Asset Management system into any PHP application. Leveraging their cloud-based infrastructure allows seamless uploading, storage, and manipulation of media assets at scale.

It also includes powerful features such as automatic format conversion, responsive image resizing, and real-time transformations, which can be easily integrated into your workflow using a simple API. This ensures your media is always optimized for performance and quality, improving user experience and site efficiency.

One of the standout features of the Cloudinary PHP SDK is its ability to perform complex image and video transformations on the fly. Developers can apply operations such as cropping, resizing, and adding overlays directly through the API without needing additional software.

This simplifies the development process and offloads the heavy lifting to Cloudinary’s servers, ensuring faster load times and reducing the burden on your own infrastructure.

Setting Up the Cloudinary PHP SDK

Composer manages the library dependency for installing Cloudinary’s PHP SDK. The PHP library should be installed directly from the packagist repository.

The prompt below allows you to update your composer.json file.

{
  "require": {
    "cloudinary/cloudinary_php": "^2"
  }
}

The dependencies and the PHP package can be installed automatically with this prompt:

composer install

Should challenges related to permission occur, run the file with the prompt:

php composer .phar install.

For the Cloudinary PHP library to function optimally, we need to configure our cloud_name. For API calls to upload images or videos, the api_key and api_secret need to be included, too. You can find these keys in the Cloudinary console dashboard.

php image gallery

Additionally, several optional configuration parameters may be needed and can be done globally with an environmental variable of the configuration: :instance method or programmatically in each call to a Cloudinary method.

Uploading Images and Videos to Cloudinary

In addition to its robust Image and Video API, Cloudinary offers a feature-rich digital asset management (DAM) product that guides users through several functionalities. These tools help developers and creatives maximize digital assets and simplify operations to provide value to the end user.

For developers who need to create and work with PHP image galleries, this feature is encapsulated in the PHP SDK. In the following sections, we’ll see how files can be managed in the PHP library – from uploading to deployment.

Starting off, uploading media to Cloudinary can be done in one of two ways:

  • Server-side upload via Cloudinary’s API
  • Direct upload from a browser through their DAM system

Let’s explore each of them.

Server-Side Upload

The server-side method involves uploading a raw file to the library using a PHP backend. The process is done over HTTPS with a secure protocol based on your environment’s api_keys and api_secret parameters.

To upload an image, the uploadApi class is used with either of these commands:

use Cloudinary\Api\Upload\UploadApi;

public function upload($file, $options = [])

For example, to upload an image with the name my_school.jpg, you should have the following prompt:

(new UploadApi())->upload('my_school.jpg')

Specific file parameters to upload include a local path, remote HTTP or HTTPS URL, a whitelisted storage bucket URL, and data stream. Different upload parameters exist, but some are specific to Cloudinary.

Uploading videos follows a similar path. However, the resource_type must be specified as “video” within the upload method. Cloudinary has a specific data size requirement for video upload. The maximum video size to upload is pegged at 20 MB. If your video file exceeds this, the PHP SDK supports automatically uploading large files in chunks. The default chunk_size parameter is 20 MB.

The command below uploads a video (dog.mp4) to Cloudinary’s PHP SDK in chunks of 6 MB and stores it in a folder with the public ID dog_closeup. The resulting video is also transformed into a square and a small rectangle.

(new UploadApi())->upload('dog.mp4', [
  'resource_type' => 'video',
  'public_id' => 'myfolder/mysubfolder/dog_closeup',
  'chunk_size' => 6000000,
  'eager' => [
    ['width' => 300, 'height' => 300, 'crop' => 'pad'], 
    ['width' => 160, 'height' => 100, 'crop' => 'crop', 'gravity' => 'south']], 
  'eager_async' => true, 
  'eager_notification_url' => 'https://mysite.example.com/notify_endpoint']
)

Once your image or video is uploaded, they are stored in the PHP image gallery and immediately available to you for transformation. The uploads will have an HTTP or HTTPS URL for easy access. Additional assets such as the public ID, resources type, width, height, file size, format, and authenticating signature will be provided.

Direct Upload from Browser

Optimizing media in your PHP image library is made simpler with direct browser uploads to Cloudinary. Instead of using the API, developers can use the Cloudinary dashboard to streamline the image upload process, enhancing efficiency and user experience. The

  1. Sign in to Cloudinary – Start by logging into your Cloudinary dashboard. If you’re new, signing up is quick and straightforward.
  2. Navigate to the Media Library – Head over to the Media Library tab once logged in. Here’s where all the magic happens.
  3. Click ‘Upload’ – Look for the “Upload” button – it’s your gateway to adding new images.
  4. Select Your Images – Choose the images you wish to upload from your device. You can select multiple files for efficiency.
  5. Optimization and Transformation – Configure your settings to automatically optimize and transform your images upon upload. This step is crucial for making sure your images are web-ready.
  6. Upload – Hit the “Upload” button and watch as your images are uploaded to the cloud, returning optimized, transformed, and ready to enhance your web projects.

In just a few clicks, you’ve managed to upload your images and ensure they’re optimized for any platform.

Image and Video Transformations with PHP

Cloudinary makes it easier for developers to create their own PHP image gallery. This is done by setting up the Cloudinary PHP SDK and uploading your desired files. Easy access to the media folder can transform the files by resizing, cropping, lightning, overlaying, and adding effects.

Cloudinary’s PHP image and video transformation lets you alter the file from its original state and perform several actions. We’ll consider the example below to further demonstrate the transformation process.

Assuming you’ve recently uploaded a file (livingroom_yellow_chairs.jpg) to your PHP image gallery and want to transform it by resizing, changing the dimension from a 250px square, and making it circular, you can search for the image in the folder and use this prompt:

use Cloudinary\Transformation\Resize;
use Cloudinary\Transformation\RoundCorners;
use Cloudinary\Transformation\Delivery;
use Cloudinary\Transformation\Format;

(new ImageTag('livingroom-yellow-chair.png'))
	->resize(Resize::fill()->width(250)
->aspectRatio(1.0))
	->roundCorners(RoundCorners::max())
	->delivery(Delivery::format(
	Format::auto()));

After transformation, the following image will be obtained.

php image gallery

Transformed Image

The same prompt above can be used to transform a video.

Managing Your Digital Assets

With the Cloudinary PHP SDK, you can upload media files seamlessly, creating a PHP image gallery. But how can you manage these files and perform functions such as renaming, deleting, and more?

With the Upload and Admin APIs, you can effectively manage, organize, and create more media assets.

The Upload API method allows you to perform several functions, such as:

  • Renaming and permanently deleting assets.
  • Adding tags, context, and structure metadata to assets.
  • Creating new assets such as text images, archives, or zipping files.
  • Modifying existing assets.

The Admin API, on the hand, facilitates:

  • Listing and restoring assets.
  • Bulk deleting of assets.
  • Managing uploads.
  • Updating existing assets
  • Performing advanced searches
  • Generating user reports.

Example of Deleting a Single Asset with Upload API

This PHP prompt example below shows how we can use the Upload API to destroy media to a video that is labelled with a public ID “Sample.”

use Cloudinary\Api\Upload\UploadApi;
$result = (new UploadApi())->destroy('sample', ['resource_type' => 'video']);

After this command, the resulting Sample becomes:

{
  "result": "ok"
}

Example of How to Use the Admin API to get the Details of an Asset

To retrieve the details of an image with the public ID “Sample,” the following PHP prompt can be used.

use Cloudinary\Api\Admin\AdminApi;
$result = (new AdminApi())->asset("sample");

After retrieving the details, the output is presented in JSON format as shown below.

{
  "asset_id": "d86882d7788f5d1d702cb63418f082a6",
  "public_id": "sample",
  "format": "jpg",
  "version": 1312461204,
  "resource_type": "image",
  "type": "upload",
  "created_at": "2017-08-04T12:33:24Z",
  "bytes": 120253,
  "width": 864,
  "height": 576,
  "url": "http://res.cloudinary.com/demo/image/upload/v1312461204/sample.jpg",
  "secure_url": "https://.../image/upload/v1312461204/sample.jpg",
  "next_cursor": "041a39fc10971b9eabd4993470f6bfaf",
  "derived": [
    {
      "transformation": "c_fill,w_100,h_100",
      "format": "jpg",
      "bytes": 7112,
      "id": "8267a869b62a93a59248f35d7f124c1f",
      "url": "http://.../demo/image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg",
      "secure_url": "https://.../image/upload/c_fill,w_100,h_100/v1312461204/sample.jpg"
    },
    {
      "transformation": "w_230,h_168,c_fit",
      "format": "jpg",
      "bytes": 19173,
      "id": "383e22a57167445552a3cdc16f0a0c85",
      "url": "http://.../demo/image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg",
      "secure_url": "https://.../image/upload/w_230,h_168,c_fit/v1312461204/sample.jpg"
    }
  ]
 }

These two examples demonstrate how far the Upload and Admin APIs can go when managing PHP media assets.

Wrap Up

Cloudinary’s PHP SDK makes it easy for developers and creatives to upload files to and manage their PHP image gallery. Our fully automated process makes it easier to not create these folders but effectively manage them and complete actions such as transformation and optimization of small to complex files.

Empower your development team with Cloudinary’s easy-to-use APIs and SDKs. Sign up for free today!

Last updated: Jun 23, 2024