index.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<?php $target_dir = "public/uploads/"; $watermark_path = "logo.png"; $output_path = "output.png"; $position = "center"; // change this to "top-left", "top-right", "center", "bottom-left", or "bottom-right" // Open the image file $image = new Imagick("1.jpg"); // Load the watermark $watermark = new Imagick($watermark_path); // Get the dimensions of the image and the watermark $image_width = $image->getImageWidth(); $image_height = $image->getImageHeight(); $watermark_width = $watermark->getImageWidth(); $watermark_height = $watermark->getImageHeight(); // Calculate the position of the watermark switch ($position) { case "top-left": $x = 0; $y = 0; break; case "top-right": $x = $image_width - $watermark_width; $y = 0; break; case "center": $x = ($image_width - $watermark_width) / 2; $y = ($image_height - $watermark_height) / 2; break; case "bottom-left": $x = 0; $y = $image_height - $watermark_height; break; case "bottom-right": default: $x = $image_width - $watermark_width; $y = $image_height - $watermark_height; break; } // Composite the watermark onto the image $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $x, $y); // Save the image to a file $image->setImageFormat('png'); $image->writeImage($output_path); echo "The image has been saved to {$output_path}"; |