想做个小工具玩玩 结果遇到了中文乱码和、背景不能透明的问题,求大神帮忙看看是咋回事。原谅我是个小白
<code><?php header("content-Type: text/html; charset=Utf-8"); //1、创建画布 $im = imagecreatetruecolor(800,800);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。 $red = imagecolorallocate($im,255,0,0); $str = iconv("gb2312","utf-8//IGNORE","大撒旦撒旦撒!hello,world"); imagestring($im,5,0,0,$str,$red);//参数说明:5-指文字的大小。函数 imagestring 不能写中文 //2、加载外部图片 $im_new = imagecreatefromjpeg("baidu.jpg");//返回图像标识符 $im_new_info = getimagesize("baidu.jpg");//取得图像大小,返回一个数组。该函数不需要用到gd库。 /*---- ****3、将加载的图片,复制到画布上 ****参数说明: $im:不用说,指的是画布; $im_new:源图片,也就是从外面加载进来的图像 (30,30):将加载进来的图像,放在画布中的位置,左上角 (0,0):表示加载的图片,从什么位置开始。(0,0)表示左上角起点,也可以只加载图片的一部分进来的 (*,*):用*表示,可以为原图片宽和高,也可以小于宽高,只截取一部分,与上面坐标一起使用,表示截取的部分 ******/ imagecopy($im,$im_new,30,30,0,0,$im_new_info[0],$im_new_info[1]);//返回布尔值 //3、输出图像 header("content-type: image/png"); imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 //4、销毁图像,释放内存 imagedestroy($im); ?></code>
回复内容:
想做个小工具玩玩 结果遇到了中文乱码和、背景不能透明的问题,求大神帮忙看看是咋回事。原谅我是个小白
<code><?php header("content-Type: text/html; charset=Utf-8"); //1、创建画布 $im = imagecreatetruecolor(800,800);//新建一个真彩色图像,默认背景是黑色,返回图像标识符。另外还有一个函数 imagecreate 已经不推荐使用。 $red = imagecolorallocate($im,255,0,0); $str = iconv("gb2312","utf-8//IGNORE","大撒旦撒旦撒!hello,world"); imagestring($im,5,0,0,$str,$red);//参数说明:5-指文字的大小。函数 imagestring 不能写中文 //2、加载外部图片 $im_new = imagecreatefromjpeg("baidu.jpg");//返回图像标识符 $im_new_info = getimagesize("baidu.jpg");//取得图像大小,返回一个数组。该函数不需要用到gd库。 /*---- ****3、将加载的图片,复制到画布上 ****参数说明: $im:不用说,指的是画布; $im_new:源图片,也就是从外面加载进来的图像 (30,30):将加载进来的图像,放在画布中的位置,左上角 (0,0):表示加载的图片,从什么位置开始。(0,0)表示左上角起点,也可以只加载图片的一部分进来的 (*,*):用*表示,可以为原图片宽和高,也可以小于宽高,只截取一部分,与上面坐标一起使用,表示截取的部分 ******/ imagecopy($im,$im_new,30,30,0,0,$im_new_info[0],$im_new_info[1]);//返回布尔值 //3、输出图像 header("content-type: image/png"); imagepng($im);//输出到页面。如果有第二个参数[,$filename],则表示保存图像 //4、销毁图像,释放内存 imagedestroy($im); ?></code>
乱码原因是因为 浏览器和文件字符集不一致
,你可以把最上面的header去掉,不去掉的话在浏览器将编码改成gb2312。
不能透明是因为你根本没设置,谈何透明。
透明系列函数是alpha,看下哪个是你需要
iconv("gb2312","utf-8//IGNORE","大撒旦撒旦撒!hello,world");
把这里面的gb2312换成gbk试试,gbk的范围更大点

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
