<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                php通用修改裁切、圓角、合并圖片: ``` <?php namespace Home\Controller; use Think\Controller; class IndexController extends Controller { /** * @todo : 本函數用于 將方形的圖片壓縮后 * 再裁減成圓形 做成logo * 與背景圖合并 * @return 返回url */ public function index1(){ //頭像 $headimgurl = 'public/log.jpg'; //背景圖 $bgurl = 'public/a.png'; $imgs['dst'] = $bgurl; //第一步 壓縮圖片 $imggzip = $this->resize_img($headimgurl); //第二步 裁減成圓角圖片 $imgs['src'] = $this->test($imggzip); //第三步 合并圖片 $dest = $this->mergerImg($imgs); } public function resize_img($url,$sizess){ $path='./'; $imgname = $path.uniqid().'.jpg'; $file = $url; list($width, $height) = getimagesize($file); //獲取原圖尺寸 $percent = ($sizess/$width); //縮放尺寸 $newwidth = $width * $percent; $newheight = $height * $percent; $src_im = imagecreatefromjpeg($file); $dst_im = imagecreatetruecolor($newwidth, $newheight); imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); imagejpeg($dst_im, $imgname); //輸出壓縮后的圖片 imagedestroy($dst_im); imagedestroy($src_im); return $imgname; } //裁切圖片 public function resize_jpg($filename,$sizess){ // $percent = 1.5; list($width, $height) = getimagesize($filename); $percent = ($sizess/$width); $new_width = $width * $percent; $new_height = $height * $percent; $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); $image_name = time() . '.jpg'; imagejpeg($image_p,$image_name); imagedestroy($image_p); imagedestroy($image); return $image_name; } //第一步生成圓角圖片 public function test($url,$path='./'){ // $w = 110; $h=110; // original size list($w, $h) = getimagesize($url); //獲取原圖尺寸 $original_path= $url; $dest_path = $path.uniqid().'.png'; $src = imagecreatefromstring(file_get_contents($original_path)); $newpic = imagecreatetruecolor($w,$h); imagealphablending($newpic,false); $transparent = imagecolorallocatealpha($newpic, 0, 0, 0, 127); $r=$w/2; for($x=0;$x<$w;$x++) for($y=0;$y<$h;$y++){ $c = imagecolorat($src,$x,$y); $_x = $x - $w/2; $_y = $y - $h/2; if((($_x*$_x) + ($_y*$_y)) < ($r*$r)){ imagesetpixel($newpic,$x,$y,$c); }else{ imagesetpixel($newpic,$x,$y,$transparent); } } imagesavealpha($newpic, true); // header('Content-Type: image/png'); imagepng($newpic, $dest_path); imagedestroy($newpic); imagedestroy($src); // unlink($url); return $dest_path; } //php 合并圖片 public function mergerImg($imgs,$path='./') { $imgname = $path.rand(1000,9999).time().'.jpg'; list($max_width, $max_height) = getimagesize($imgs['dst']); $dests = imagecreatetruecolor($max_width, $max_height); $dst_im = imagecreatefrompng($imgs['dst']); imagecopy($dests,$dst_im,0,0,0,0,$max_width,$max_height); imagedestroy($dst_im); $src_im = imagecreatefrompng($imgs['src']); $src_info = getimagesize($imgs['src']); print_r($imgname); //png合并必須使用imagecopy,否則透明部分無法透明 imagecopy($dests,$src_im,500,202,0,0,$src_info[0],$src_info[1]); imagedestroy($src_im); imagejpeg($dests,$imgname); // unlink($imgs['dst']); unlink($imgs['src']); return $imgname; } public function index(){ $imgname = './'.rand(1000,9999).time().'.jpg'; //頭像 $src = 'public/log.jpg'; //背景圖 $dst = 'data:image/jpeg;base64,/9j/4AAQSkZJRg';//圖片二進制流文件 $dst = 'public/ceshi.jpg'; //得到原始圖片信息 $dst_im = $this->imagecretefrom_type($dst); $dst_info = getimagesize($dst); //水印圖像 $srcs = 'public/log.jpg'; $srcsa = $this->resize_jpg($srcs,660); $src = $this->yj_img($srcsa); $src_im = $this->imagecretefrom_type($src); $src_info = getimagesize($src); //水印透明度 $alpha = 100; imagealphablending($src_im, true); imagesavealpha($src_im, false); //合并水印圖片 imagecopy($dst_im,$src_im,$dst_info[0]/2-$src_info[0]/2, $dst_info[1]/2-$src_info[1]/2,0,0,$src_info[0], $src_info[1] ); header('Content-Type: image/jpeg'); header('Content-Type: image/png'); //輸出合并后水印圖片 imagejpeg($dst_im,$imgname); $PSize = filesize($imgname); $picturedata = fread(fopen($imgname, "r"), $PSize); imagedestroy($dst_im); imagedestroy($src_im); unlink($src); unlink($srcsa); echo $picturedata; } public function imagecretefrom_type($imgpath){ $ext = pathinfo($imgpath); $src_img = null; switch ($ext['extension']) { case 'jpg': $src_img = imagecreatefromjpeg($imgpath); break; case 'png': $src_img = imagecreatefrompng($imgpath); break; } return $src_img; } public function yj_img($imgpath){ $imgname = rand(1000,9999).uniqid().'.png'; $ext = pathinfo($imgpath); $src_img = null; switch ($ext['extension']) { case 'jpg': $src_img = imagecreatefromjpeg($imgpath); break; case 'png': $src_img = imagecreatefrompng($imgpath); break; } $wh = getimagesize($imgpath); $w = $wh[0]; $h = $wh[1]; $w = min($w, $h); $h = $w; $img = imagecreatetruecolor($w, $h); //這一句一定要有 imagesavealpha($img, true); //拾取一個完全透明的顏色,最后一個參數127為全透明 $bg = imagecolorallocatealpha($img, 255, 255, 255, 127); imagefill($img, 0, 0, $bg); $r = $w / 2; //圓半徑 $y_x = $r; //圓心X坐標 $y_y = $r; //圓心Y坐標 for ($x = 0; $x < $w; $x++) { for ($y = 0; $y < $h; $y++) { $rgbColor = imagecolorat($src_img, $x, $y); if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) { imagesetpixel($img, $x, $y, $rgbColor); } } } imagesavealpha($img, true); imagepng($img, $imgname); imagedestroy($img); imagedestroy($src_img); return $imgname; } public function curl_post_https($url,$data){ // 模擬提交數據函數 $curl = curl_init(); // 啟動一個CURL會話 curl_setopt($curl, CURLOPT_URL, $url); // 要訪問的地址 curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 對認證證書來源的檢查 curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 從證書中檢查SSL加密算法是否存在 curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模擬用戶使用的瀏覽器 curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自動跳轉 curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自動設置Referer curl_setopt($curl, CURLOPT_POST, 1); // 發送一個常規的Post請求 curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的數據包 curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 設置超時限制防止死循環 curl_setopt($curl, CURLOPT_HEADER, 0); // 顯示返回的Header區域內容 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 獲取的信息以文件流的形式返回 $tmpInfo = curl_exec($curl); // 執行操作 if (curl_errno($curl)) { echo 'Errno'.curl_error($curl);//捕抓異常 } curl_close($curl); // 關閉CURL會話 return $tmpInfo; // 返回數據,json格式 } public function index2(){ $url = 'https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=52_GwppN6xcxomP3F2vufbO-cQCSvH4_W901vq9mE8YrZ_R7Kv-wycOFUpUlAt2dtHtXQ7QChMsvasKJln8D3ob66n_nl7csTbVsfXrwe17duZ3TUcKB_1TL2rQXsr0ehdmQntqzv_S8n89RHd6JMDeAFAQTK'; $arr['page'] = 'pages/index/index'; $arr['scene'] = 'a=1'; $arr['check_path'] = true; $arr['env_version'] = 'release'; $datas = json_encode($arr); $data = $this->curl_post_https($url,$datas); print_r(json_encode($data)); } } ``` 運行以下代碼時: ~~~lisp imagecreatefrompng('http://imgur.com/NUl4v.png'); ~~~ 我得到一個錯誤: > **PHP警告**:imagecreatefrompng()*\[function.imagecreatefrompng\]*:無法讀取/home/test/...中的圖像數據 PNG文件似乎很好-我可以用不同的編輯器打開它,并且Unix`file`命令報告它是: > `PNG image, 640 x 360, 8-bit/color RGB, non-interlaced` 我不知道為什么,但是以下方法可行: ~~~reasonml imagecreatefromstring(file_get_contents('http://imgur.com/NUl4v.png')); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看