PHP generates an image in two ways

Source: Internet
Author: User
PHP generates an image in two ways: GD

// Default logoprivate function generation_default_img ($ width, $ height, $ img_type, $ output_url) {// check whether the default logo exists if (file_exists ($ output_url) {return ;} else {// create a true color image and return an image Identifier header ('content-Type: image/png '); $ im = imagecreate ($ width, $ height ); // assign color $ bg_color = imagecolorallocate ($ im, 255,255,255); // draw a rectangle and fill it with imagefilledrectangle ($ im, 0, 0, $ width, $ height, $ bg_color); imagepng ($ im, $ output_url); imagedestroy ($ im );}}



Method 2: Imagick

// Default logoprivate function generation_default_img ($ width, $ height, $ img_type, $ output_url) {// Build the canvas $ obj_default = new Imagick (); $ obj_default-> newimage ($ width, $ height, 'white'); $ obj_default-> setimageformat ($ img_type); $ obj_default-> writeimage ($ output_url ); $ obj_default-> clear (); // destroy the object $ obj_default-> destroy ();}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.