Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that php can't generate pictures

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces "php can not generate pictures how to solve", in the daily operation, I believe that many people in the php can not generate pictures on how to solve the problem, the editor consulted all kinds of data, sorted out a simple and easy-to-use method of operation, hope to answer the "php can not generate pictures how to solve" doubts! Next, please follow the editor to study!

Solution.

1. Open the gd2 library and view it through phpinfo. Clear bom, and the code starts at the top line, so the problem may be on the code.

2. Add the ob_clean () statement before header, and then you can run it.

Pay attention

When generating a picture, header ('Content-type: image/png'); cannot be preceded by output. Or, precede it with: ob_clean (); you can clear the output cache even with output.

Solve an example

/ / set the height width of CAPTCHA\ the number of characters above $img_w = 70; $img_h = 22; $font = 5; $char_len = 5; / / array merge, range () function returns a range array of $char = array_merge (range ('ajar,' z'), range ('cause,' Z'), range ('1th,' 9'); $rand_keys = array_rand ($char, $char_len) / / randomly fetch a specified number of elements from the array to generate the key value if ($char_len = = 1) {/ / if there is only one number, array_rand () returns the non-array type $rand_keys = array ($rand_keys);} shuffle ($rand_keys); / / can not use $code ='; foreach ($rand_keys as $k) {$code. = $char [$k];} session_start () $_ SESSION ['captcha'] = $code; / / add lines, colors / / create a new image $img = imagecreatetruecolor ($img_w, $img_h); / / assign colors $bg_color = imagecolorallocate ($img, 0xcc, 0xcc, 0xcc); / / canvas background color imagefill ($img, 0,0, $bg_color); / / interference lines for ($I = 0; $I < 300) + $I) {$color = imagecolorallocate ($img, mt_rand (0255), mt_rand (0255), mt_rand (0255)); imagesetpixel ($img, mt_rand (0, $img_w), mt_rand (0, $img_h), $color);} for ($I = 0; $I

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report