PHP to add a border to a picture

Source: Internet
Author: User

/** * Add border to picture by Liangjian 2014-06-19 * @param $ImgUrl picture address * @param $SavePath new picture save path * @param $px border pixel * @return ambigous &L T;boolean, path to new picture > */function imageaddboard ($ImgUrl, $SavePath, $px = 2) {$aPathInfo = PathInfo ($IMGURL);//File name $sfil ename = $aPathInfo [' filename '];//picture extension $sextension = $aPathInfo [' extension '];//get the original size $size = getimagesize ($IMGURL); $ img_w = $size [0]; $img _h = $size [1];//read picture if (Strtolower ($sExtension) = = ' png ') {$resource = Imagecreatefrompng ($Im Gurl);} ElseIf (Strtolower ($sExtension) = = ' jpg ' | | strtolower ($sExtension) = = ' jpeg ') {$resource = Imagecreatefromjpeg ($I Mgurl);} 282*282 Black background Image $im = @imagecreatetruecolor (($img _w + $px), ($img _h + $px)) or Die ("Cannot Initialize new GD image s Tream ");//Create a background for the true color canvas and set it to transparent $color = imagecolorallocate ($im, 0, 0, 0)//imagefill ($im, 0, 0, $color);//imagecolortr  Ansparent ($im, $color);//Put the brand logo image on a black background image, the border is 1pximagecopy ($im, $resource, $px/2, $PX/2, 0, 0, $size [0], $size [1]); $imgNewUrl = $SavePath. $sFileName. '-N. '. $sExtension, if (strtolower ($sExtension) = = ' png ') {$ret = Imagepng ($im, $IMGNEWURL);} elseif (Strtolower ($sExtensi ON) = = ' jpg ' | | Strtolower ($sExtension) = = ' jpeg ') {$ret = imagejpeg ($im, $IMGNEWURL);} Imagedestroy ($im); return $ret? $IMGNEWURL: false;}

Use:

$savePath = './brand/'; $url = ' http://cdn0.xx.cn/store/moudlepic/301_module_images/936001_z.jpg '; Var_dump ( Imageaddboard ($url, $savePath));

Before adding:

After adding:

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.