/** * 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: