php圖形圖像處理

jopen 9年前發布 | 892 次閱讀 PHP

<?php

header("content-type:image/jpeg");

/一、簡單的圖像輸出/ $im = imagecreate(60,40); $pink = imagecolorallocate($im,35, 25,220); imagejpeg($im);

//imagestring($im,16, 200, 200,"I LOVE YOU",);

/ 二、將字符串寫入到圖片中 / //載入圖片 $me=imagecreatefromjpeg("../../images/3.jpg"); //設置字體顏色 $text_color = imagecolorallocate($me, 255,84,0); //設置的字體的位置 $font = "C:\Windows\Fonts\simkai.ttf"; //要寫入的字符串 $str = iconv('GBK',"UTF-8", "php開發..."); //將字符串寫入到圖片中 imagettftext($me,20,0,50,50, $text_color,$font, $str); //輸出圖片 imagejpeg($me); //釋放資源 imagedestroy($me);</pre>

session_start();
header("content-type:image/jpeg");
//驗證碼
//圖像寬度
$image_width =65;
//圖像高度
$image_height =45;
//設置隨機數的種子
//srand(microtime()*1000);

for ($i=0;$i<6;$i++){ $new_str .=dechex(rand(0, 100)); } $_SESSION[code]=$new_str;

$image = imagecreate($image_width, $image_height); imagecolorallocate($image,rand(0,255), rand(0,255),rand(0,255));

for ($i=0;$i<strlen($_SESSION[code]);$i++){ $font = mt_rand(3, 8);//生成隨機字體大小 $x = mt_rand(3,10)+$image_width*$i/4; $y = mt_rand(3,$image_height/4); $color = imagecolorallocate($image,mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); imagestring($image, $font, $x, $y,$_SESSION[code][$i], $color); } imagepng($image); imagedestroy($image);</pre>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!