$image = imagecreatefromjpeg('original.jpg'); $logo = imagecreatefrompng('logo.png'); // Set the position of the logo $logo_x = imagesx($image) - imagesx($logo) - 10; $logo_y = imagesy($image) - imagesy($logo) - 10; // Add the logo to the image imagecopy($image, $logo, $logo_x, $logo_y, 0, 0, imagesx($logo), imagesy($logo)); // Save the new image imagejpeg($image, 'new.jpg'); // Free up memory imagedestroy($image); imagedestroy($logo);
$image = new Imagick('original.jpg'); $text = new Imagick(); $text->newImage(200, 50, new ImagickPixel('transparent')); // Set the text properties $text->setFont('Arial'); $text->setGravity(Imagick::GRAVITY_SOUTHEAST); $text->setFillColor(new ImagickPixel('#ffffff')); $text->setFillOpacity(0.5); $text->setStrokeColor(new ImagickPixel('#000000')); $text->setStrokeOpacity(0.5); // Add the text to the image $text->annotateImage($image, 10, 10, 0, 'Watermark'); // Save the new image $image->writeImage('new.jpg'); // Free up memory $image->destroy(); $text->destroy();This code uses the Imagick library to load an original image and create a new Imagick object for the text. It then sets the properties of the text such as font, color, and opacity, and adds it to the original image using the `annotateImage` function. Finally, it saves the new image and frees up memory. In both examples, we used PHP image processing libraries such as GD and Imagick.