When we upload images on a website, many users need to add watermarks to images. Next we will explain in detail
Sample Code for implementing a Chinese watermark in the php gd library:
- <? Php
- $ Im = imagecreatetruecolor (100,100 );
- // Create a true color image
- $ White = imagecolorallocate ($ im, 255,235,255 );
- // Assign color to an image, which is different from my design knowledge ..
I have never thought of assigning colors to the specified image logo during painting.
.. This function is often mixed with the imagefill function.
- Imagefill ($ im, 0, 0, $ white );
- // Fill the area
- $ Black = imagecolorallocate ($ im, 250,50, 50 );
- // Assign color to an image
- Imagerectangle ($ im, 5, 5, 50, 50, $ black );
- // Draw a rectangle
- Header ("Content-type: image/jpeg ");
- // Send the header and use imagejpeg to directly output the image in the browser.
- Imagejpeg ($ im, 'imagename', 100 );
- // Output an image name and quality
- Imagedestroy ($ im );
- // Release the memory associated with the image. Image
Is the image identifier returned by the image creation function.
- ?>
Implement Chinese watermark code in php gd library
- <? Php
- Header ("Content-type: image/png ");
- /* Notify the browser to output the image */
- $ Im = imagecreate (400,300 );
- /* Define the image size */
- $ Gray = ImageColorAllocate ($ im, 235,235,235 );
- $ Pink = ImageColorAllocate ($ im, 255,128,255 );
- /*
- $ Fontfile = "C: WINDOWSFontsSIMHEI. TTF ";
- Sorry, this sentence is always stuck and lost after submission. I don't know what's going on.
The comments to be tested are now tested.
- */
- /* $ Fontfile font path, depending on the operating system, can be
Simhei. ttf (), SIMKAI. TTF (),
SIMFANG. TTF (), SIMSUN. TTC (&)
Chinese fonts supported by GD */
- $ Str = iconv ('gb2312', 'utf-8', 'Chinese watermark !!! ');
- /* Convert the gb2312 character set to the UTF-8 Character Set */
- ImageTTFText ($ im, 30, 0, 50,140,
$ Pink, $ fontfile, $ str );
- /* Add a Chinese watermark */
- Imagepng ($ im );
- ImageDestroy ($ im );
- ?>
The above is a summary of the methods for implementing Chinese watermarks in the php gd library.