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 StandardizationLaravel
The response header is processed, so youconsole
You will findHeader
Header 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 ',]);});