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 53 54 55 56 57 58 59 60 61 |
<?php $target_dir = "public/uploads"; $watermark_path = "logo.png"; $output_path = "output.webp"; $position = "bottom-right"; $image = imagecreatefromjpeg("1.jpg"); if(!$image){ die("Could not open the image file"); } // load the watermark $watermark = imagecreatefrompng($watermark_path); if(!$watermark){ die("Could not open the watermark file"); } // get the dimenstions of the image and the watermark $image_width = imagesx($image); $image_height = imagesy($image); $watermark_width = imagesx($watermark); $watermark_height = imagesy($watermark); switch($position){ case "top-left": $dest_x = 10; $dest_y = 10; break; case "top-right": $dest_x = $image_width - $watermark_width - 10; $dest_y = 10; break; case "center": $dest_x = ($image_width - $watermark_width) / 2; $dest_y = ($image_height - $watermark_height) / 2; break; case "bottom-left": $dest_x = 10; $dest_y = $image_height - $watermark_height - 10; break; case "bottom-right": $dest_x = $image_width - $watermark_width - 10; $dest_y = $image_height - $watermark_height - 10; break; } imagecopy($image,$watermark,$dest_x,$dest_y,0,0,$watermark_width,$watermark_height); imagewebp($image,$output_path); imagedestroy($image); imagedestroy($watermark); echo "The image has been saved to {$output_path}"; |