PHP Chinese text watermark garbled, seeking enlighten

Source: Internet
Author: User
PHP Chinese text watermark garbled, beg enlighten
This post was last edited by zhangrun1 on 2012-12-03 11:43:19

Several encoding settings:
File:

Head:

Code:

Results:

Detailed code:






<title>Default Examples</title>



/*
* Function: PHP image watermark (watermark supports picture or text)
Parameters
* $groundImage background image, that is, need to add a watermark image, temporarily only support gif,jpg,png format;
* $waterPos watermark position, there are 10 kinds of states, 0 is a random position;
* 1 for the top left, 2 for the top center, 3 for the top right;
* 4 for the middle of the left, 5 for the Middle center, 6 for the middle right;
* 7 for the bottom of the left, 8 for the bottom center, 9 for the bottom of the right;
* $waterImage image watermark, that is, as a watermark image, temporarily only support gif,jpg,png format;
* $waterText text watermark, that is, the text as a watermark, support ASCII code, does not support Chinese;
* $textFont Text size, value 1, 2, 3, 4 or 5, default is 5;
* $textColor text color, value is hexadecimal color value, default is #ff0000 (red);
*
* Note: Support GD 2.0,support FreeType, gif Read, GIF Create, JPG, PNG
* $waterImage and $waterText best not to use at the same time, choose one of them, priority to use the $waterImage.
* When the $waterimage is valid, the parameters $waterstring, $stringFont, $stringColor are not effective.
* The watermark image has the same file name as the $groundImage.
* Author: longware @ 2004-11-3 14:15:13
*/
function Imagewatermark ($groundImage, $waterPos = 0, $waterImage = "", $waterText = "", $textFont = 5, $textColor = "#FF00 00 ") {
$isWaterImage = FALSE;
$FORMATMSG = "Does not support this file format, please use the picture processing software to convert the picture to GIF, JPG, PNG format. ";

Read Watermark File
if (! empty ($waterImage) && file_exists ($waterImage)) {
$isWaterImage = false;
$water _info = getimagesize ($waterImage);
$water _w = $water _info [0]; Get the width of the watermark picture
$water _h = $water _info [1]; Get a high watermark image


Switch ($water _info [2])//Get the format of the watermark picture
{
Case 1:
$water _im = imagecreatefromgif ($waterImage);
Break
Case 2:
$water _im = Imagecreatefromjpeg ($waterImage);
Break
Case 3:
$water _im = imagecreatefrompng ($waterImage);
Break
Default:
Die ($FORMATMSG);
}
}

Read background picture
if (! empty ($groundImage) && file_exists ($groundImage)) {
$ground _info = getimagesize ($groundImage);
$ground _w = $ground _info [0]; Get the width of the background image
$ground _h = $ground _info [1]; Get a high background picture


Switch ($ground _info [2])//Get background picture format
{
Case 1:
$ground _im = imagecreatefromgif ($groundImage);
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.