php 创建一张图片,PHP 生成一张图片的两种步骤

PHP 生成一张图片的两种方法

方法一:GD

//默认的logo

private function generation_default_img($width,$height,$img_type,$output_url)

{

//检查默认logo是否存在

if(file_exists($output_url))

{

return;

}

else

{

//新建一个真彩色图像,返回一个图像标识符

header ('Content-Type: image/png');

$im = imagecreate($width, $height);

//分配颜色

$bg_color = imagecolorallocate($im, 255, 255, 255);

//画一个矩形并填充

imagefilledrectangle($im, 0, 0, $width, $height, $bg_color);

imagepng($im,$output_url);

imagedestroy($im);

}

}

方法二:Imagick

//默认的logo

private function generation_default_img($width,$height,$img_type,$output_url)

{

//构建画布

$obj_default = new Imagick();

$obj_default -> newimage($width, $height, 'white');

$obj_default -> setimageformat($img_type);

$obj_default -> writeimage($output_url);

$obj_default -> clear();

//销毁对象

$obj_default -> destroy();

}