What are the advantages and disadvantages of using CLI commands versus PHP code for image watermarking tasks?

When it comes to image watermarking tasks, using CLI commands can be advantageous for their simplicity and efficiency in handling bulk processing. On the other hand, using PHP code provides more flexibility and control over the watermarking process but may be slower compared to CLI commands.

// PHP code for image watermarking
$sourceImage = 'input.jpg';
$watermark = 'watermark.png';
$outputImage = 'output.jpg';

$source = imagecreatefromjpeg($sourceImage);
$watermark = imagecreatefrompng($watermark);

$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);

imagecopy($source, $watermark, 10, 10, 0, 0, $watermarkWidth, $watermarkHeight);

imagejpeg($source, $outputImage);