通常我们要创建图像时会使用
//创建画布
$img=imagecreate(500,500);
$path = './test.jpeg';
获取图片信息,调用不同方法
//获取图片信息
$img_info = getimagesize($path);
//获取图片类型,jpg等
$type = image_type_to_extension($info[2], false);
//获取相应方法
$func = "imagecreatefrom{$type}";
但当我们要获取已有的图片进行处理时,可以使用 imagecreatefromjpeg 方法
//$img=imagecreatefromjpeg('https://b-ssl.duitang.com/uploads/item/201607/04/20160704052649_WLyfB.jpeg');
$img=$func($path);
代码如下
//$img=imagecreatefromjpeg('https://b-ssl.duitang.com/uploads/item/201607/04/20160704052649_WLyfB.jpeg');
$path = './test.jpeg';
//获取图片信息
$img_info = getimagesize($path);
//获取图片类型,jpg等
$type = image_type_to_extension($info[2], false);
//获取相应方法
$func = "imagecreatefrom{$type}";
$img=$func($path );
//设置颜色
//背景色
$white=imagecolorallocate($img,255,255,255);
//画笔
$black=imagecolorallocate($img,0,0,0);
//矩形
imagerectangle($img,100,100,300,300,$black);
ob_clean();
header('Content-type:image/jpeg');
imagejpeg($img) or die('创建图形失败');
imagedestroy($img);
?>