1. <strong id="7actg"></strong>
    2. <table id="7actg"></table>

    3. <address id="7actg"></address>
      <address id="7actg"></address>
      1. <object id="7actg"><tt id="7actg"></tt></object>

        phpimagephp 處理圖片處理文字合集

        聯(lián)合創(chuàng)作 · 2023-09-29 15:58

        phpimage 是一個(gè) PHP 環(huán)境下的圖片處理工具,裁剪+水印+文字+壓縮+識別等。

        1.圖片合成,兩張圖片合成一張圖片

            //目標(biāo)圖片透明的地方不透明了,也就是說png透明的會(huì)被當(dāng)做白色處理
            //imagecopymerge ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h , int $pct )---拷貝并合并圖像的一部分
            //將 src_im 圖像中坐標(biāo)從 src_x,src_y 開始,寬度為 src_w,高度為 src_h 的一部分拷貝到 dst_im 圖像中坐標(biāo)為 dst_x 和 dst_y 的位置上。兩圖像將根據(jù) pct 來決定合并程度,其值范圍從 0 到 100。當(dāng) pct = 0 時(shí),實(shí)際上什么也沒做,當(dāng)為 100 時(shí)對于調(diào)色板圖像本函數(shù)和 imagecopy() 完全一樣,它對真彩色圖像實(shí)現(xiàn)了 alpha 透明
            public function doMerge($dis, $src, $newImg)
            {
                $imageD = imagecreatefrompng($dis);//目標(biāo)圖
                $imageS = imagecreatefrompng($src);
                
                imagecopymerge($imageD, $imageS, 0, 0, 0,0, imagesx($imageS), imagesy($imageS), 0);;
                imagepng($imageD, $newImg);//bool(true)
            }

        2.圖片壓縮

            //源文件,新的寬,新的高
            //return 新文件的地址
            public function zoomImg($file, $nw, $nh)
            {
                $nfile = '/tmp/shuiyin/zoom.png';
                $new = imagecreatetruecolor($nw, $nh);
                list($width, $height) = getimagesize($file);
                $img = imagecreatefromjpeg($file);
        
                imagecopyresized($new, $img,0, 0,0, 0, $nw, $nh, $width, $height);
        
                imagejpeg($new, $nfile);
                imagedestroy($new);
                imagedestroy($img);
                return $nfile;
            }

        3.向圖片寫入文件

            /**
             * PHP實(shí)現(xiàn)圖片上寫入實(shí)現(xiàn)文字自動(dòng)換行
             * @param $fontsize 字體大小
             * @param $angle 角度
             * @param $font 字體路徑
             * @param $string 要寫在圖片上的文字
             * @param $width 預(yù)先設(shè)置圖片上文字的寬度
             * @param $flag  換行時(shí)單詞不折行
             */
            public function wordWrap($fontsize,$angle,$font,$string,$width,$flag=true) {
                $content = "";
                if($flag){
                    $words = explode(" ",$string);
                    foreach ($words as $key=>$value) {
                        $teststr = $content." ".$value;
                        $testbox = imagettfbbox($fontsize, $angle, $font, $teststr);
                        if(($testbox[2] > $width)) {
                            $content .= "\n";
                        }
                        $content .= $value." ";
                    }
                } else {
                    for ($i=0;$i<mb_strlen($string);$i++) {
                        $letter[] = mb_substr($string, $i, 1);
                    }
                    foreach ($letter as $l) {
                        $teststr = $content." ".$l;
                        $testbox = imagettfbbox($fontsize, $angle, $font, $teststr);
                        // 判斷拼接后的字符串是否超過預(yù)設(shè)的寬度
                        if (($testbox[2] > $width) && ($content !== "")) {
                            $content .= "\n";
                        }
                        $content .= $l;
                    }
        
                }
                return $content;
            }

        4.等等,圖片文字處理相關(guān)功能會(huì)繼續(xù)升級更新

        備注:調(diào)用舉例

                //寫入文字***********時(shí)期
                $config['file'] = "/tmp/shuiyin/shuiyin_ret.png";
                $config['nFile'] = "/tmp/shuiyin/shuiyin_ret_1.png";//日期
                $config['size'] = 32; 
                $config['width'] = 600;
                $config['angle'] = 0;
                $config['fontfile'] = "/tmp/shuiyin/msyh.ttc";
                $config['x'] = 56; 
                $config['y'] = 1345;
                $font = new \Phpmedia\Font\WordsOnImg($config);
                $content = $font->writeWordsToImg($day, false);
        

         

        瀏覽 22
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        評論
        圖片
        表情
        推薦
        點(diǎn)贊
        評論
        收藏
        分享

        手機(jī)掃一掃分享

        編輯 分享
        舉報(bào)
        1. <strong id="7actg"></strong>
        2. <table id="7actg"></table>

        3. <address id="7actg"></address>
          <address id="7actg"></address>
          1. <object id="7actg"><tt id="7actg"></tt></object>
            国产精品无码久久久久久免费 | 欧美成综合 | AAAAA毛片 | 亚洲97人人视 | 欧美成人免费在线视频 | 国产校园春色 | 樱桃视频91 | poronovideo少妇喷潮 | 国产一级a毛一级a毛视频在线网站 | 91免费国产精品 |