php兩張圖片合併一張,加文字,並壓縮

qq_1913284695發表於2016-09-30
function HBImg($path_2){
$path_1 = "../xx/xx.jpg";
$image_1 = imagecreatefromjpeg($path_1);
$image_2 = imagecreatefromjpeg($path_2);//可以是http://xxx.vv的資源圖片
$image_3 = imageCreatetruecolor(imagesx($image_1),imagesy($image_1));
imagecopymerge($image_3,$image_1,0,0,0,0,imagesx($image_1),imagesy($image_1),100);
list($width,$height)=getimagesize($path_2);
imagecopyresampled($image_3,$image_2,40,550,0,0,230,230,$width,$width);
$pic_name="fv".time()."_".rand(1000,9999).".jpg";
imagejpeg($image_3,"../xx/".$pic_name,50);
imagedestroy($image_3);
$path="http://xxx.xx/".$pic_name;
return $path;

}


function hebingImg($path_1,$path_2,$uname){//加文字
$image_1 = imagecreatefromjpeg($path_1);

$textcolor = imagecolorallocate($image_1, 255, 255,255); //設定水印字型顏色  
    $font = 'font/0.ttf'; //定義字型  
    imagettftext($image_1, 50, 0, 90, 180, $textcolor, $font, $uname);//將文字寫到圖片中  
          
        
$image_2 = imagecreatefromjpeg($path_2);
$image_3 = imageCreatetruecolor(imagesx($image_1),imagesy($image_1));
imagecopymerge($image_3,$image_1,0,0,0,0,imagesx($image_1),imagesy($image_1),100);
list($width,$height)=getimagesize($path_2);
imagecopyresampled($image_3,$image_2,70,305,0,0,300,450,$width,$height);
$pic_name="SYY_".time()."_".rand(1000,9999).".jpg";
imagejpeg($image_3,"../img/".$pic_name,50);
imagedestroy($image_3);
$path="http://xxx/".$pic_name;
return $path;
}



function https_post($url, $data) {
$curl = curl_init ();
curl_setopt ( $curl, CURLOPT_URL, $url );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, FALSE );
curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, FALSE );
if (! empty ( $data )) {
curl_setopt ( $curl, CURLOPT_POST, 1 );
curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
}
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
$output = curl_exec ( $curl );
curl_close ( $curl );
return $output;
}
function https_get($url) {
$output = file_get_contents($url);;
return $output;
}

相關文章