Method One: GD
<span style= "White-space:pre" ></span>//default Logoprivate function generation_default_img ($width, $height, $img _type, $output _url) {//check if the default logo exists if (file_exists ($output _url)) {return;} else{//Create a new true color image and return an image identifier header (' Content-type:image/png '); $im = Imagecreate ($width, $height); <span style= "White-space:pre" ></span>//assign color <span style= "White-space:pre" ></span> $BG _color = Imagecolorallocate ($im, 255, 255, 255); <span style= "White-space:pre" ></span> //Draw a rectangle and fill < Span style= "White-space:pre" ></span> imagefilledrectangle ($im, 0, 0, $width, $height, $BG _color); <span style= "White-space:pre" ></span>imagepng ($im, $output _url); <span style= "White-space:pre" > </span> Imagedestroy ($im);}}
Method Two: Imagick
<span style= "White-space:pre" ></span>//default Logoprivate function generation_default_img ($width, $height, $img _type, $output _url) {//Build canvas <span style= "White-space:pre" ></span> $obj _default = new Imagick (); <span style= "White-space:pre" ></span> $obj _default newimage ($width, $height, ' White '); <span Style= "White-space:pre" ></span> $obj _default-Setimageformat ($img _type); <span style= "White-space:pre" ></span> $obj _default writeimage ($output _url); <span style= " White-space:pre "></span> $obj _default, Clear (); <span style= "White-space:pre" ></span>//destroying objects <span style= "White-space:pre" ></span> $ Obj_default-Destroy ();}
Two ways to generate a picture in PHP