PHP对图片资源进行左右上下拼接两种方法

/*

欢迎使用贪夜php函数

分析一些自己写的免费函数可供调用,边学习,边分享,小白学习,大佬勿喷

更多可进QQ群:951387336;

贪夜QQ:2899133851


 

*/

    function picStitching_u_d($path1,$path2) {

        //上下合成图片

        //path1-图片1路径,path2-图片2路径

     $photo1 = $path1;

     $photo2 = $path2;

     $photo1info = getimagesize ($photo1);

     $photo2info = getimagesize ($photo2);

     

     $photo1width = $photo1info[0];

     $photo1height = $photo1info[1];

     

     $photo2width = $photo2info[0];

     $photo2height= $photo2info[1];

     

     $initwidth = max (array($photo1width,$photo2width));

     $initheight = $photo1height + $photo2height;

     //创建画布

     $image = imagecreatetruecolor($initwidth, $initheight);

     //合成图片

    imagecopyresized($image ,imagecreatefromjpeg($photo1),0, 0, 0, 0,$photo1width,$photo1height,$photo1width,$photo1height);  

    imagecopyresized($image,imagecreatefromjpeg($photo2),0,$photo1height, 0, 0,$initwidth,$photo2height,$photo2width,$photo2height);

    //协议头

    ob_clean();

    header ("Content-Type:image/jpeg");

    //输出图片

    imagejpeg($image);

    //销毁图片

    imagedestroy($image);

    }  

    function picStitching_l_r($path1,$path2) {

        //左右合成图片

        //path1-图片1路径,path2-图片2路径

     $photo1 = $path1;

     $photo2 = $path2;

     $photo1info = getimagesize ($photo1);

     $photo2info = getimagesize ($photo2);

     

     $photo1width = $photo1info[0];

     $photo1height = $photo1info[1];

     

     $photo2width = $photo2info[0];

     $photo2height= $photo2info[1];

     

     $initwidth = $photo1width+$photo2width;

     $initheight = max(array($photo1height,$photo2height));

     //创建画布

     $image = imagecreatetruecolor($initwidth, $initheight);

     //合成图片

     imagecopyresized($image ,imagecreatefromjpeg($photo1),0, 0, 0, 0,$photo1width,$initheight,$photo1width,$photo1height);  

     imagecopyresized($image,imagecreatefromjpeg($photo2),$photo1width,0, 0, 0,$photo2width,$initheight,$photo2width,$photo2height);

    //协议头

    ob_clean();

    header ("Content-Type:image/jpeg");

    //输出图片

    imagejpeg($image);

    //销毁图片

    imagedestroy($image);

    }  

你可能感兴趣的:(PHP教程,php)