百度AI黑白图片上色源码

发布时间:2020-02-27 15:56:51 热度: 672 ℃ 评论数: 2
$code = $_FILES['file'];
//图片加水印开始
function createWater($dst_path , $src_path ){
//创建图片的实例
$dst = imagecreatefromstring(file_get_contents($dst_path));
$src = imagecreatefromstring(file_get_contents($src_path));
//获取水印图片的宽高
list($src_w, $src_h) = getimagesize($src_path);
//获取原图片宽高
list($src_w_p, $src_h_p) = getimagesize($dst_path);
//将水印图片复制到目标图片右下角,最后个参数50是设置透明度,这里实现半透明效果
imagecopy($dst, $src, $src_w_p - $src_w - 10 , $src_h_p - $src_h -10, 0, 0, $src_w, $src_h);
//输出图片
list($dst_w, $dst_h, $dst_type) = getimagesize($dst_path);
switch ($dst_type) {
case 1://GIF
header('Content-Type: image/gif');
imagegif($dst,$dst_path);
break;
case 2://JPG
header('Content-Type: image/jpeg');
imagejpeg($dst,$dst_path);
break;
case 3://PNG
header('Content-Type: image/png');
imagepng($dst,$dst_path);
break;
default:
break;
}
imagedestroy($dst);
imagedestroy($src);
}
//图片加水印结束
if(is_uploaded_file($_FILES['file']['tmp_name'])) {
$uploaded_file=$_FILES['file']['tmp_name'];
$user_path="upload/ss";
if(!file_exists($user_path)) {
mkdir($user_path,0777,true);
}

$file_true_name=$_FILES['file']['name'];
$move_to_file=$user_path."/".time().rand(1,1000)."-".date("Y-m-d").substr($file_true_name,strrpos($file_true_name,"."));
if(move_uploaded_file($uploaded_file,iconv("utf-8","gb2312",$move_to_file))) {

//$dst_path = './timg.jpeg';
//水印图片
$src_path = './data/logo.png';

createWater($move_to_file,$src_path);
$images = file_get_contents($move_to_file);
$img_encode = base64_encode($images);
$url="http://shangse.w7d7.com/api/public/api/index/index";
$param=array(
"image"=>"data:image/jpeg;base64,".$img_encode,
);
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_POST, 1 );
curl_setopt ( $ch, CURLOPT_HEADER, 0 );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_POSTFIELDS, $param );
$return = curl_exec ( $ch );
curl_close ( $ch );

print_r($return);

} else {
echo "上传失败".date("Y-m-d H:i:sa");

}
}


百度AI,黑白图片上色,php源码

吐槽一下
  • 消灭零回复

手机扫码访问