PHP generates image and text watermarks. Many readers sent emails asking me how to use PHP to generate a watermark. today I will explain it to you. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and water. many readers sent an email asking me how to use PHP to generate a watermark. today I will explain it to you. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and watermark_image (). You can integrate the examples in this tutorial into your WEB project, such as uploading the copyright watermark of an image.
Text watermark
We use the watermark_text () function to generate a text watermark. you must first specify the font source file, font size, and font text. the specific code is as follows:
- $font_path = "GILSANUB.TTF"; // Font file
- $font_size = 30; // in pixcels
- $water_mark_text_2 = "phpfuns"; // Watermark Text
- function watermark_text($oldimage_name, $new_image_name)
- {
- global $font_path, $font_size, $water_mark_text_2;
- list($owidth,$oheight) = getimagesize($oldimage_name);
- $width = $height = 300;
- $image = imagecreatetruecolor($width, $height);
- $image_src = imagecreatefromjpeg($oldimage_name);
- imagecopyresampled($image, $image_src, 0, 0, 0, 0, $width, $height, $owidth, $oheight);
- $blue = imagecolorallocate($image, 79, 166, 185);
- imagettftext($image, $font_size, 0, 68, 190, $blue, $font_path, $water_mark_text_2);
- imagejpeg($image, $new_image_name, 100);
- imagedestroy($image);
- unlink($oldimage_name);
- return true;
- }
Here you can
Bytes. This PHP Tutorial uses two functions to generate watermarks: watermark_text () and water...