>  기사  >  백엔드 개발  >  php图形图像处理

php图形图像处理

WBOY
WBOY원래의
2016-07-25 08:42:431008검색
  1. header("content-type:image/jpeg");
  2. /*一、简单的图像输出*/
  3. $im = imagecreate(60,40);
  4. $pink = imagecolorallocate($im,35, 25,220);
  5. imagejpeg($im);
  6. //imagestring($im,16, 200, 200,"I LOVE YOU",);
  7. /* 二、将字符串写入到图片中 */
  8. //载入图片
  9. $me=imagecreatefromjpeg("../../images/3.jpg");
  10. //设置字体颜色
  11. $text_color = imagecolorallocate($me, 255,84,0);
  12. //设置的字体的位置
  13. $font = "C:\Windows\Fonts\simkai.ttf";
  14. //要写入的字符串
  15. $str = iconv('GBK',"UTF-8", "php开发...");
  16. //将字符串写入到图片中
  17. imagettftext($me,20,0,50,50, $text_color,$font, $str);
  18. //输出图片
  19. imagejpeg($me);
  20. //释放资源
  21. imagedestroy($me);
复制代码

  1. session_start();
  2. header("content-type:image/jpeg");
  3. //验证码
  4. //图像宽度
  5. $image_width =65;
  6. //图像高度
  7. $image_height =45;
  8. //设置随机数的种子
  9. //srand(microtime()*1000);
  10. for ($i=0;$i $new_str .=dechex(rand(0, 100));
  11. }
  12. $_SESSION[code]=$new_str;
  13. $image = imagecreate($image_width, $image_height);
  14. imagecolorallocate($image,rand(0,255), rand(0,255),rand(0,255));
  15. for ($i=0;$i $font = mt_rand(3, 8);//生成随机字体大小
  16. $x = mt_rand(3,10)+$image_width*$i/4;
  17. $y = mt_rand(3,$image_height/4);
  18. $color = imagecolorallocate($image,mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
  19. imagestring($image, $font, $x, $y,$_SESSION[code][$i], $color);
  20. }
  21. imagepng($image);
  22. imagedestroy($image);
复制代码

图像处理, php


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.