生成图片 图片缩放 图片圆角

4 篇文章 0 订阅
3 篇文章 0 订阅
 public function hebing(){
        global $_W;
         $id = $_W['merchuid'];
	    $merchname = $_W['merch_user']['merchname'];
	    $starttime = date('Y-m-d H:i:s',$_W['merch_user']['start_time']);
	    $endtime = date('Y-m-d H:i:s',$_W['merch_user']['end_time']);
        $img = "https://".$_SERVER['SERVER_NAME']."/attachment/images/1/merch/5/iPxOTDx06tGKoOT4b54K664UTuns26.png";
        $a = $this->zhengdingma($_W['merchuid'],1);
        $logo1 = 'https://'.$_SERVER['SERVER_NAME']."/attachment/".$_W['merch_user']['logo'];
        $a_im = imagecreatefromstring($a);//征订码
        $logo_im = imagecreatefromjpeg($logo1);//logo
        $img_im = imagecreatefrompng($img);
        $m_img1=imagecreatetruecolor(500, 500);  //固定大小的缩放 
        list($s_w,$s_h)=getimagesize($logo1);//获取logo图片大小
        list($img_w,$img_h)=getimagesize($img);//获取图片大小
        $log_img = imagecreatetruecolor($s_w, $s_h);//固定大小的缩放
        $white=imagecolorallocate($img_im, 248, 248, 248);//创建颜色
        $blue=imagecolorallocate($img_im, 0, 0, 255);
        $black=imagecolorallocate($img_im, 0, 0, 0);
        $green=imagecolorallocate($img_im, 0, 255, 0);
        $gray=imagecolorallocate($img_im, 204, 204, 204);
        imagerectangle($img_im, 40, 100, 300, 480, $white);//画矩形
        imagefilledrectangle($img_im,40, 100, 300, 480, $white);//填充矩形
        $font = IA_ROOT . "/addons/ewei_shopv2/static/fonts/msyh.ttf";
        $merchname1 =$merchname."校服订购";
        $time = "征订时间:".$starttime."至".$endtime;
        $tixing = $merchname."提醒您:";
        $fontSize = 14;
        //  imagettftext($img_im, 15, 0,45, 50, $white, $font, $merchname1);//写文字
         $fontBox = imagettfbbox($fontSize, 0, $font, $merchname1);//获取文字所需的尺寸大小 
         imagettftext($img_im, $fontSize, 0, ceil(($img_w - $fontBox[2]) / 2), 45, $white, $font, $merchname1);//文字居中
         
         imagettftext($img_im, 8, 0,30, 80, $white, $font, $time);
         imagettftext($img_im, 12, 0,50, 140, $black, $font, $tixing);
         imagettftext($img_im, 9, 0,60, 160, $black, $font, "订购工作开始了,为了方便学生家长,请用");
         imagettftext($img_im, 9, 0,60, 185, $black, $font, "微信扫码进行征订!");
         imagettftext($img_im, 9, 0,60, 390, $gray, $font, "长按识别小程序码或打开微信扫描进行征订");
         imagettftext($img_im, 9, 0,50, 420, $gray, $font, "-此次征订由西安依呀呀文化用品有限公司提供-");
        imagecopyresized($img_im, $a_im, 65, 190, 0, 0, 180, 180,420,420);//码
        imagecopyresized($img_im,$logo_im, 126, 250, 0, 0, 62, 62,$s_w,$s_h);//logo560,560
        imageellipse($img_im,  157,281,87, 87, $white);     //画一个矩形不填充
        imageellipse($img_im, 157,282,64, 64, $white);      //画一个椭圆(圆)不填充
        imagefilltoborder($img_im,159, 246,$white,$white);//遇到指定颜色就不填充
        
        header("content-type: image/png");
        imagepng($img_im);
    }

	/**
     * 图片缩放
     * @param bool $image
     * @param int $zoom
     * @return resource
     */

    private function imageZoom($image = false, $zoom = 2)// $image = imagecreatefromjpeg($avatar);
    {
		

        $width = imagesx($image);
        $height = imagesy($image);
        $target = imagecreatetruecolor($width * $zoom, $height * $zoom);
        imagecopyresampled($target, $image, 0, 0, 0, 0, $width * $zoom, $height * $zoom, $width, $height);
        imagedestroy($image);
        return $target;
    }

    /**
     * 图片圆角
     * @param bool $target
     * @param bool $circle
     * @return resource
     */

    private function imageRadius($target = false, $circle = false) $image = imagecreatefromjpeg($avatar);
    {
        $w = imagesx($target);
        $h = imagesy($target);
        $w = min($w, $h);
        $h = $w;
        $img = imagecreatetruecolor($w, $h);
        imagesavealpha($img, true);
        $bg = imagecolorallocatealpha($img, 255, 255, 255, 127);
        imagefill($img, 0, 0, $bg);
        $radius = ($circle ? $w / 2 : 20);
        $r = $radius;
        for( $x = 0; $x < $w; $x++ ) 
        {
            for( $y = 0; $y < $h; $y++ ) 
            {
                $rgbColor = imagecolorat($target, $x, $y);
                if( $radius <= $x && $x <= $w - $radius || $radius <= $y && $y <= $h - $radius ) 
                {
                    imagesetpixel($img, $x, $y, $rgbColor);
                }
                else
                {
                    $y_x = $r;
                    $y_y = $r;
                    if( ($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r ) 
                    {
                        imagesetpixel($img, $x, $y, $rgbColor);
                    }

                    $y_x = $w - $r;
                    $y_y = $r;
                    if( ($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r ) 
                    {
                        imagesetpixel($img, $x, $y, $rgbColor);
                    }

                    $y_x = $r;
                    $y_y = $h - $r;
                    if( ($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r ) 
                    {
                        imagesetpixel($img, $x, $y, $rgbColor);
                    }

                    $y_x = $w - $r;
                    $y_y = $h - $r;
                    if( ($x - $y_x) * ($x - $y_x) + ($y - $y_y) * ($y - $y_y) <= $r * $r ) 
                    {
                        imagesetpixel($img, $x, $y, $rgbColor);
                    }

                }

            }
        }
        return $img;
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值