How to Add a Watermark to a Video using PHP?

In video production, watermarking is the process of placing an image, text, or logo on top of a video for various purposes, such as branding, adding captions, or overlaying visual elements onto existing video files. If you want to put a watermark in a video using PHP, you'll need a video editing API. Here's a quick and easy way to achieve this in your own PHP application using just a few lines of code:

Input Code
// Don't forget to install the required library using Composer:
// composer require creatomate/creatomate
$client = new Creatomate\Client('Your API Key');

$output = $client->render([
 'source' => new Creatomate\Source([
  'output_format' => 'mp4',
  'elements' => [
   [
    'type' => 'video',
    'source' => 'https://cdn.creatomate.com/demo/mountains.mp4'
   ],
   [
    'type' => 'image',
    'source' => 'https://cdn.creatomate.com/demo/logo.png',
    'x' => '100%',
    'y' => '0%',
    'width' => '60 vmin',
    'height' => '60 vmin',
    'x_padding' => '7 vmin',
    'y_padding' => '7 vmin',
    'x_anchor' => '100%',
    'y_anchor' => '0%',
    'x_alignment' => '100%',
    'y_alignment' => '0%',
    'shadow_color' => 'rgba(0,0,0,0.66)',
    'fit' => 'contain'
   ]
  ]
 ])
]);

var_dump($output);
Output Video

How it works: First, install the Creatomate package from Packagist using Composer. In this example, we have two main elements: the background video and a watermark image that will be placed on top of it. Here we can use any video or image file, as long as it can be accessed through a public URL.

The watermark image, in this case a logo, is positioned in the top-right corner of the scene. We achieve this by adjusting the "x" and "y" properties, along with the "x_anchor" and "y_anchor" properties. Additionally, we add some spacing between the logo and the video edges using the "padding" property.

It's important to note that all properties are defined using relative units like "vmin" and "%". This allows the overlay to adapt dynamically to the background video, ensuring responsiveness and compatibility with various video formats, including horizontal, vertical, and square videos.

You can create your own overlay with the online video editor below. This online tool enables you to design customized video layouts and export them as JSON for seamless integration into your PHP applications, for all your dynamic video editing needs.

Edit this Code Example in the Video Editor

Easily design your own video templates using the online editor. Then, export your templates as JSON and integrate them into your PHP application to create any kind of video – completely through code.

Related PHP Video Editing Questions

Start automating today

Start with a full-featured trial with 50 credits, no credit card required.
Get started for free