Use Laravel to develop and display images

Source: Internet
Author: User
First, write the native php code in PHP. The Code is as follows: {code...} the problem is: Version: LaravelFrameworkversion5.1.35 (LTS)

First, write the native php code in PHP.

The Code is as follows:

Route: get ('png ', function () {ob_start (); $ im = @ imagecreate (200, 50) or die ("image resource creation failed "); imagecolorallocate ($ im, 255,255,255); $ text_color = imagecolorallocate ($ im, 0, 0,255); imagestring ($ im, 5, 0, 0, "Hello world! ", $ Text_color); imagepng ($ im); imagedestroy ($ im); $ content = ob_get_clean (); return response ($ content, 200, ['content-type' => 'image/png ',]);});

The problem is:

Version: Laravel Framework version 5.1.35 (LTS)

Reply content:

First, write the native php code in PHP.

The Code is as follows:

Route: get ('png ', function () {ob_start (); $ im = @ imagecreate (200, 50) or die ("image resource creation failed "); imagecolorallocate ($ im, 255,255,255); $ text_color = imagecolorallocate ($ im, 0, 0,255); imagestring ($ im, 5, 0, 0, "Hello world! ", $ Text_color); imagepng ($ im); imagedestroy ($ im); $ content = ob_get_clean (); return response ($ content, 200, ['content-type' => 'image/png ',]);});

The problem is:

Version: Laravel Framework version 5.1.35 (LTS)

$ Im = @ imagecreate (200, 50) or die ("image resource creation failed"); imagecolorallocate ($ im, 255,255,255); $ text_color = imagecolorallocate ($ im, 0, 0,255); imagestring ($ im, 5, 0, 0, "Hello world! ", $ Text_color); ob_start (); imagepng ($ im); $ content = ob_get_contents (); imagedestroy ($ im); ob_end_clean (); return $ response = Response :: make ($ content)-> header ('content-type', 'image/png ');

It should be for StandardizationLaravelThe response header is processed, so youconsoleYou will findHeaderHeader information is overwritten. It is best to have onereturn.

Use ob_clean () before output (),

This is the result after adjustment by the above programmers. Thank you!

Route: get ('png ', function () {ob_clean (); ob_start (); $ im = @ imagecreate (200, 50) or die ("An error occurred while creating image resources"); imagecolorallocate ($ im, 255,255,255); $ text_color = imagecolorallocate ($ im, 0, 0,255); imagestring ($ im, 5, 0, 0, "Hello world! ", $ Text_color); imagepng ($ im); imagedestroy ($ im); $ content = ob_get_clean (); return response ($ content, 200, ['content-type' => 'image/png ',]);});

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.