PHP构造验证码
代码如下:
<?phpheader ('Content-type:image/jpeg');$width=120;$height=40;$element=array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z');$string='';for ($i=0;$i<5;$i++){<span style="white-space:pre"> $string.=$element[rand(0,count($element)-1)];}$img=imagecreatetruecolor($width, $height);//设置图片大小$colorBg=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));//随机产生背景色$colorBorder=imagecolorallocate($img,rand(200,255),rand(200,255),rand(200,255));//随机产生背景色$colorString=imagecolorallocate($img,rand(10,100),rand(10,100),rand(10,100));imagefill($img,0,0,$colorBg);//设置图片背景色imagerectangle($img,0,0,$width-1,$height-1,$colorBorder);//构建矩形边框for($i=0;$i imagesetpixel($img,rand(0,$width-1),rand(0,$height-1),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));//画一个单一的像素}for($i=0;$i imageline($img,rand(0,$width/2),rand(0,$height),rand($width/2,$width),rand(0,$height),imagecolorallocate($img,rand(100,200),rand(100,200),rand(100,200)));<span style="white-space:pre"> </span>//前两个为起点坐标,后两个为终点坐标,起点控制在左半边,终点控制在右半边}//imagestring($img,5,0,0,'abcd',$colorString);imagettftext($img,14,rand(-5,5),rand(5,15),rand(30,35),$colorString,'font/SketchyComic.ttf',$string);//绘制文字,可以选择丰富的字体的方法//说明:array imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )imagejpeg($img);imagedestroy($img);
重点介绍imagettftext()方法:
- image
- 图像资源。见 imagecreatetruecolor()。
- size
- 字体大小。根据 GD 版本不同,应该以像素大小指定(GD1)或点大小(GD2)。
- angle
- 角度制表示的角度,0 度为从左向右读的文本。更高数值表示逆时针旋转。例如 90 度表示从下向上读的文本。
- x
- 由 x,y 所表示的坐标定义了第一个字符的基本点(大概是字符的左下角)。这和imagestring() 不同,其 x,y 定义了第一个字符的左上角。例如 "top left" 为 0, 0。
- y
- Y 坐标。它设定了字体基线的位置,不是字符的最底端。
- color
- 颜色索引。使用负的颜色索引值具有关闭防锯齿的效果。见 imagecolorallocate()。
- fontfile
-
是想要使用的 TrueType 字体的路径。 根据 PHP 所使用的 GD 库的不同,当fontfile 没有以/ 开头时则.ttf 将被加到文件名之后并且会在库定义字体路径中尝试搜索该文件名。当使用的 GD 库版本低于 2.0.18 时,一个空格字符 而不是分号将被用来作为不同字体文件的“路径分隔符”。不小心使用了此特性将会导致一条警告信息:Warning: Could not find/open font。对受影响的版本来说唯一解决方案就是将字体移动到不包含空格的路径中去。
很多情况下字体都放在脚本的同一个目录下。下面的小技巧可以减轻包含的问题。
<span style="color:rgb(0,0,187)"><?php <br></span><span style="color:rgb(255,128,0)">// Set the enviroment variable for GD<br></span><span style="color:rgb(0,0,187)">putenv</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(221,0,0)">'GDFONTPATH=' </span><span style="color:rgb(0,119,0)">. </span><span style="color:rgb(0,0,187)">realpath</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(221,0,0)">'.'</span><span style="color:rgb(0,119,0)">));<br><br></span><span style="color:rgb(255,128,0)">// Name the font to be used (note the lack of the .ttf extension)<br></span><span style="color:rgb(0,0,187)">$font </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(221,0,0)">'SomeFont'</span><span style="color:rgb(0,119,0)">;<br></span><span style="color:rgb(0,0,187)">?></span>
- text
- 文本字符串。 可以包含十进制数字化字符表示(形式为:€)来访问字体中超过位置 127 的字符。UTF-8 编码的字符串可以直接传递。如果字符串中使用的某个字符不被字体支持,一个空心矩形将替换该字符。
imagettftext() 返回一个含有 8 个单元的数组表示了文本外框的四个角,顺序为坐下角,右下角,右上角,左上角。这些点是相对于文本的而和角度无关,因此“左上角”指的是以水平方向看文字时其左上角。
Example #1 imagettftext() 例子
本例中的脚本将生成一个白色的 400x30 像素 PNG 图像,其中有黑色(带灰色阴影)Arial 字体写的“Testing...”。
<span style="color:rgb(0,0,187)"><?php <br></span><span style="color:rgb(255,128,0)">// Set the content-type<br></span><span style="color:rgb(0,0,187)">header</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(221,0,0)">"Content-type: image/png"</span><span style="color:rgb(0,119,0)">);<br><br></span><span style="color:rgb(255,128,0)">// Create the image<br></span><span style="color:rgb(0,0,187)">$im </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(0,0,187)">imagecreatetruecolor</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">400</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">30</span><span style="color:rgb(0,119,0)">);<br><br></span><span style="color:rgb(255,128,0)">// Create some colors<br></span><span style="color:rgb(0,0,187)">$white </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(0,0,187)">imagecolorallocate</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">255</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">255</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">255</span><span style="color:rgb(0,119,0)">);<br></span><span style="color:rgb(0,0,187)">$grey </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(0,0,187)">imagecolorallocate</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">128</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">128</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">128</span><span style="color:rgb(0,119,0)">);<br></span><span style="color:rgb(0,0,187)">$black </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(0,0,187)">imagecolorallocate</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">);<br></span><span style="color:rgb(0,0,187)">imagefilledrectangle</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">399</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">29</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$white</span><span style="color:rgb(0,119,0)">);<br><br></span><span style="color:rgb(255,128,0)">// The text to draw<br></span><span style="color:rgb(0,0,187)">$text </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(221,0,0)">'Testing...'</span><span style="color:rgb(0,119,0)">;<br></span><span style="color:rgb(255,128,0)">// Replace path by your own font path<br></span><span style="color:rgb(0,0,187)">$font </span><span style="color:rgb(0,119,0)">= </span><span style="color:rgb(221,0,0)">'arial.ttf'</span><span style="color:rgb(0,119,0)">;<br><br></span><span style="color:rgb(255,128,0)">// Add some shadow to the text<br></span><span style="color:rgb(0,0,187)">imagettftext</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">20</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">11</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">21</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$grey</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$font</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$text</span><span style="color:rgb(0,119,0)">);<br><br></span><span style="color:rgb(255,128,0)">// Add the text<br></span><span style="color:rgb(0,0,187)">imagettftext</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">20</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">0</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">10</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">20</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$black</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$font</span><span style="color:rgb(0,119,0)">, </span><span style="color:rgb(0,0,187)">$text</span><span style="color:rgb(0,119,0)">);<br><br></span><span style="color:rgb(255,128,0)">// Using imagepng() results in clearer text compared with imagejpeg()<br></span><span style="color:rgb(0,0,187)">imagepng</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">);<br></span><span style="color:rgb(0,0,187)">imagedestroy</span><span style="color:rgb(0,119,0)">(</span><span style="color:rgb(0,0,187)">$im</span><span style="color:rgb(0,119,0)">);<br></span><span style="color:rgb(0,0,187)">?></span>

여전히 인기있는 것은 사용 편의성, 유연성 및 강력한 생태계입니다. 1) 사용 편의성과 간단한 구문은 초보자에게 첫 번째 선택입니다. 2) 웹 개발, HTTP 요청 및 데이터베이스와의 우수한 상호 작용과 밀접하게 통합되었습니다. 3) 거대한 생태계는 풍부한 도구와 라이브러리를 제공합니다. 4) 활성 커뮤니티와 오픈 소스 자연은 새로운 요구와 기술 동향에 맞게 조정됩니다.

PHP와 Python은 웹 개발, 데이터 처리 및 자동화 작업에 널리 사용되는 고급 프로그래밍 언어입니다. 1.PHP는 종종 동적 웹 사이트 및 컨텐츠 관리 시스템을 구축하는 데 사용되며 Python은 종종 웹 프레임 워크 및 데이터 과학을 구축하는 데 사용됩니다. 2.PHP는 Echo를 사용하여 콘텐츠를 출력하고 Python은 인쇄를 사용합니다. 3. 객체 지향 프로그래밍을 지원하지만 구문과 키워드는 다릅니다. 4. PHP는 약한 유형 변환을 지원하는 반면, 파이썬은 더 엄격합니다. 5. PHP 성능 최적화에는 Opcache 및 비동기 프로그래밍 사용이 포함되며 Python은 Cprofile 및 비동기 프로그래밍을 사용합니다.

PHP는 주로 절차 적 프로그래밍이지만 객체 지향 프로그래밍 (OOP)도 지원합니다. Python은 OOP, 기능 및 절차 프로그래밍을 포함한 다양한 패러다임을 지원합니다. PHP는 웹 개발에 적합하며 Python은 데이터 분석 및 기계 학습과 같은 다양한 응용 프로그램에 적합합니다.

PHP는 1994 년에 시작되었으며 Rasmuslerdorf에 의해 개발되었습니다. 원래 웹 사이트 방문자를 추적하는 데 사용되었으며 점차 서버 측 스크립팅 언어로 진화했으며 웹 개발에 널리 사용되었습니다. Python은 1980 년대 후반 Guidovan Rossum에 의해 개발되었으며 1991 년에 처음 출시되었습니다. 코드 가독성과 단순성을 강조하며 과학 컴퓨팅, 데이터 분석 및 기타 분야에 적합합니다.

PHP는 웹 개발 및 빠른 프로토 타이핑에 적합하며 Python은 데이터 과학 및 기계 학습에 적합합니다. 1.PHP는 간단한 구문과 함께 동적 웹 개발에 사용되며 빠른 개발에 적합합니다. 2. Python은 간결한 구문을 가지고 있으며 여러 분야에 적합하며 강력한 라이브러리 생태계가 있습니다.

PHP는 현대화 프로세스에서 많은 웹 사이트 및 응용 프로그램을 지원하고 프레임 워크를 통해 개발 요구에 적응하기 때문에 여전히 중요합니다. 1.PHP7은 성능을 향상시키고 새로운 기능을 소개합니다. 2. Laravel, Symfony 및 Codeigniter와 같은 현대 프레임 워크는 개발을 단순화하고 코드 품질을 향상시킵니다. 3. 성능 최적화 및 모범 사례는 응용 프로그램 효율성을 더욱 향상시킵니다.

phphassignificallyimpactedwebdevelopmentandextendsbeyondit

PHP 유형은 코드 품질과 가독성을 향상시키기위한 프롬프트입니다. 1) 스칼라 유형 팁 : PHP7.0이므로 int, float 등과 같은 기능 매개 변수에 기본 데이터 유형을 지정할 수 있습니다. 2) 반환 유형 프롬프트 : 기능 반환 값 유형의 일관성을 확인하십시오. 3) Union 유형 프롬프트 : PHP8.0이므로 기능 매개 변수 또는 반환 값에 여러 유형을 지정할 수 있습니다. 4) Nullable 유형 프롬프트 : NULL 값을 포함하고 널 값을 반환 할 수있는 기능을 포함 할 수 있습니다.


핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

드림위버 CS6
시각적 웹 개발 도구

mPDF
mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경
