transparente marca agua agregar php image watermark

agregar - marca de agua php transparente



Agrega ''Marca de agua'' a las imágenes con php (7)

Encontré una solución mucho mejor que agrega una marca de agua dinamicamente a través de .htaccess, puede encontrar el tutorial aquí:

Agregar marca de agua a las imágenes a través de htaccess

Después de cargar el archivo .htaccess personalizado, el filtro de agua.php y su imagen watermark.png, todas las imágenes de la carpeta y sus subcarpetas mostrarán la marca de agua, sin embargo, aún conservará el archivo original en el servidor.

Espero que ayude a alguien de la misma manera que me ayudó.

Tengo un sitio web donde los usuarios pueden subir imágenes ...

Necesito agregar mi logotipo (marca de agua) a las imágenes una vez que se cargan.

¿Como lo puedo hacer?

Y es importante que la marca de agua esté en una esquina donde será visible, por ejemplo, he visto sitios web que generan una marca de agua sobre la marcha, y coloca la marca dondequiera que el fondo de la imagen principal sea "del mismo color", por lo que marca de agua sobresale si sabes lo que quiero decir.

¿Alguien tiene un buen tutorial o artículo sobre esto? ¿O conozco alguna función en php que necesitaría encontrar la posición de la marca de agua?



Un buen ejemplo en el manual de PHP:

// Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng(''stamp.png''); $im = imagecreatefromjpeg(''photo.jpeg''); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Copy the stamp image onto our photo using the margin offsets and the photo // width to calculate positioning of the stamp. imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); // Output and free memory header(''Content-type: image/png''); imagepng($im); imagedestroy($im);


usa esta función
el tipo de imagen de marca de agua debe ser "png"

function watermark_image($target, $wtrmrk_file, $newcopy) { $watermark = imagecreatefrompng($wtrmrk_file); imagealphablending($watermark, false); imagesavealpha($watermark, true); $img = imagecreatefromjpeg($target); $img_w = imagesx($img); $img_h = imagesy($img); $wtrmrk_w = imagesx($watermark); $wtrmrk_h = imagesy($watermark); $dst_x = ($img_w / 2) - ($wtrmrk_w / 2); // For centering the watermark on any image $dst_y = ($img_h / 2) - ($wtrmrk_h / 2); // For centering the watermark on any image imagecopy($img, $watermark, $dst_x, $dst_y, 0, 0, $wtrmrk_w, $wtrmrk_h); imagejpeg($img, $newcopy, 100); imagedestroy($img); imagedestroy($watermark); } watermark_image(''image_name.jpg'',''watermark.png'', ''new_image_name.jpg'');


ImageMagick funciona bien para eso. Lo he hecho antes. Sin embargo, todo el asunto es un poco doloroso. Especialmente si quieres sofisticados modos de fusión y cosas por el estilo.


Buen ejemplo de imagen de marca de agua y posicionado en el centro

<?php // Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng(''stampimg.png''); $im = imagecreatefrompng(''mainimage.png''); // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); $imgx = imagesx($im); $imgy = imagesy($im); $centerX=round($imgx/2); $centerY=round($imgy/2); // Copy the stamp image onto our photo using the margin offsets and the photo // width to calculate positioning of the stamp. imagecopy($im, $stamp, $centerX, $centerY, 0, 0, imagesx($stamp), imagesy($stamp)); // Output and free memory header(''Content-type: image/png''); imagepng($im); imagedestroy($im); ?>


// Load the stamp and the photo to apply the watermark to $stamp = imagecreatefrompng(''stamp.png''); $im = imagecreatefromjpeg(''photo.jpg''); $save_watermark_photo_address = ''watermark_photo.jpg''; // Set the margins for the stamp and get the height/width of the stamp image $marge_right = 10; $marge_bottom = 10; $sx = imagesx($stamp); $sy = imagesy($stamp); // Copy the stamp image onto our photo using the margin offsets and the photo // width to calculate positioning of the stamp. imagecopy($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp)); // Output and free memory // header(''Content-type: image/png''); imagejpeg($im, $save_watermark_photo_address, 80); imagedestroy($im);