PHP

HOW TO ADD WATERMARK TO IMAGE IN PHP

CREATE IMAGE OBJECT $img = imagecreatefromjpeg("IMG.JPG");

DEFINE COLOR $red = imagecolorallocatealpha($img, 255, 0, 0);

ADD TEXT WATERMARK (A)

01

WRITE WATERMARK TEXT TO IMAGE imagettftext($img, 18, 0, 0, 24, $red, "PATH\FONT.TTF", "COPYRIGHT");

SAVE WATERMARKED IMAGE imagejpeg($img, "WATERMARKED.JPG", 100);

ADD TEXT WATERMARK (B)

02

LOAD IMAGE + WATERMARK $i = imagecreatefromjpeg("IMG.JPG"); $w = imagecreatefrompng("WM.PNG");

IMAGE DIMENSIONS $ww = imagesx($w); $wh = imagesy($w);

ADD IMAGE WATERMARK (A)

03

APPLY WATERMARK imagecopy ($i, $w, 0, 0, 0, 0, $ww, $wh);

SAVE WATERMARKED IMAGE imagejpeg($img, "WATERMARKED.JPG", 100);

ADD IMAGE WATERMARK (B)

04