Add a logo to a picture anywhere

Source: Internet
Author: User
The principle of this is to place the logo ' picture ' in the specified position.
The steps are as follows:
1. Get basic information on images and logos
GetImageSize

2. Determine the image resource type and create the corresponding picture resource
Getpictype (Custom Function)

3. Get the location coordinates of the logo
Getlocal (Custom Function)

4. Draw the logo up
Imagecopyresampled

5. Output image
Outputimage (Custom Function)

6. Releasing picture resources
Imagedestroy

Effect:

The code is as follows:

/** * @function Add logo to image * @param $picname * @param $logo * @param int $local lo Go Add location: 1: Top left, 2: Upper right, 3: Lower left, 4: Lower right, 5: Top, 6: Middle, 7: Lower * @param string $pre * @return return a new picture name */ functionaddlogo($picname,$logo,$local="1" ,$pre="L_"){$picInfo= GetImageSize ($picname);//Get basic information about a picture$logoInfo= GetImageSize ($logo);//Get basic information about your logo$picW=$picInfo[0];//Get pic width$picH=$picInfo[1];//Get pic height$logoW=$logoInfo[0];//Get logo width$logoH=$logoInfo[1];//Get logo height//Get the picture resource type and create the corresponding picture resource$picim= Getpictype ($picInfo[2],$picname);$logoim= Getpictype ($logoInfo[2],$logo);//Paint the logo$XY= Getlocal ($local,$picW,$picH,$logoW,$logoH);//Get the location coordinates of the logoImagecopyresampled ($picim,$logoim,$XY[0],$XY[1],0,0,$logoW,$logoH,$logoW,$logoH);//Output image$newPicName= Outputimage ($picname,$pre,$picim);//Release picture ResourcesImagedestroy ($picim); Imagedestroy ($logoim);return$newPicName;}/** * @function Get the coordinates of the upper-left corner of the corresponding position * @param $local position * @param $picW picture width * @param $pi CH Picture High * @param $logoW logo width * @param $logoH logo high * @return return wide array */ functiongetlocal($local,$picW,$picH,$logoW ,$logoH){$XY=Array();Switch($local)    { Case1:$XY=Array(0,0); Break; Case2:$XY=Array($picW-$logoW,0); Break; Case3:$XY=Array(0,$picH-$logoH); Break; Case4:$XY=Array($picW-$logoW,$picH-$logoH); Break; Case5:$XY=Array($picW/2-$logoW/2,0); Break; Case6:$XY=Array($picW/2-$logoW/2,$picH/2-$logoH/2); Break; Case7:$XY=Array($picW/2-$logoW/2,$picH-$logoH); Break;default: die("No support for logo additions in this location"); Break; }return$XY;}/** * function to determine and return the type of picture (returned as Resource) * @param int $type picture type * @param string $picname picture name * @retu RN returns the corresponding picture resource * / functiongetpictype($type,$picname){$im=NULL;Switch($type)    { Case1://gif$im= Imagecreatefromgif ($picname); Break; Case2://jpg$im= Imagecreatefromjpeg ($picname); Break; Case3://png$im= Imagecreatefrompng ($picname); Break; Case4://bmp$im= Imagecreatefromwbmp ($picname); Break;default: die("Don't know the picture type"); Break; }return$im;}/** * Function Output image * @param string $picname picture name * @param string $pre new picture name prefix * @param Reso Urse $nim the image resource to output * @return return a new picture name * / functionoutputimage($picname,$pre,$nim){ $info= GetImageSize ($picname);$picInfo= PathInfo ($picname);$newPicName=$picInfo[' dirname '].'/'.$pre.$picInfo[' basename '];//path to output fileSwitch($info[2])    { Case1: Imagegif ($nim,$newPicName); Break; Case2: imagejpeg ($nim,$newPicName); Break; Case3: Imagepng ($nim,$newPicName); Break; Case4: Imagewbmp ($nim,$newPicName); Break; }return$newPicName;}

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above is introduced to the image anywhere add logo, including aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.