php图像处理函数例子汇总,php图片函数实例代码

WBOY
Lepaskan: 2016-07-25 08:51:42
asal
844 orang telah melayarinya
  1. imagecolorsforindex()

  2. imagecolorat()
  3. 在图片上画图形 $img=imagecreatefromgif("./images/map.gif");
  4. /**

  5. * 图片锐化处理
  6. * edit by bbs.it-home.org
  7. */
  8. $red= imagecolorallocate($img, 255, 0, 0);
  9. imageline($img, 0, 0, 100, 100, $red);

  10. imageellipse($img, 200, 100, 100, 100, $red);
  11. imagegif($img, "./images/map2.gif");
  12. imagedestroy($img);
复制代码

图片普通缩放

  1. function thumn($background, $width, $height, $newfile) {
  2. list($s_w, $s_h)=getimagesize($background);//获取原图片高度、宽度
  3. if ($width && ($s_w $width = ($height / $s_h) * $s_w;
  4. } else {
  5. $height = ($width / $s_w) * $s_h;
  6. }
  7. $new=imagecreatetruecolor($width, $height);
  8. $img=imagecreatefromjpeg($background);
  9. imagecopyresampled($new, $img, 0, 0, 0, 0, $width, $height, $s_w, $s_h);
  10. imagejpeg($new, $newfile);
  11. imagedestroy($new);
  12. imagedestroy($img);
  13. }
  14. thumn("images/hee.jpg", 200, 200, "./images/hee3.jpg");
复制代码

gif透明色处理

  1. /**

  2. * 图片裁剪处理
  3. * edit by bbs.it-home.org
  4. */
  5. function cut($background, $cut_x, $cut_y, $cut_width, $cut_height, $location){

  6. $back=imagecreatefromjpeg($background);
  7. $new=imagecreatetruecolor($cut_width, $cut_height);
  8. imagecopyresampled($new, $back, 0, 0, $cut_x, $cut_y, $cut_width, $cut_height,$cut_width,$cut_height);
  9. imagejpeg($new, $location);
  10. imagedestroy($new);
  11. imagedestroy($back);
  12. }
  13. cut("./images/hee.jpg", 440, 140, 117, 112, "./images/hee5.jpg");
  14. ?>
复制代码

图片加水印 文字水印

  1. /**

  2. *
  3. * 图片添加文字水印
  4. */
  5. function mark_text($background, $text, $x, $y){

  6. $back=imagecreatefromjpeg($background);
  7. $color=imagecolorallocate($back, 0, 255, 0);
  8. imagettftext($back, 20, 0, $x, $y, $color, "simkai.ttf", $text);
  9. imagejpeg($back, "./images/hee7.jpg");
  10. imagedestroy($back);
  11. }
  12. mark_text("./images/hee.jpg", "细说PHP", 150, 250);
  13. //图片水印
  14. function mark_pic($background, $waterpic, $x, $y){
  15. $back=imagecreatefromjpeg($background);
  16. $water=imagecreatefromgif($waterpic);
  17. $w_w=imagesx($water);
  18. $w_h=imagesy($water);
  19. imagecopy($back, $water, $x, $y, 0, 0, $w_w, $w_h);
  20. imagejpeg($back,"./images/hee8.jpg");
  21. imagedestroy($back);
  22. imagedestroy($water);
  23. }
  24. mark_pic("./images/hee.jpg", "./images/gaolf.gif", 50, 200);
复制代码

图片旋转

  1. /**

  2. * 图片旋转
  3. * edit by bbs.it-home.org
  4. */
  5. $back=imagecreatefromjpeg("./images/hee.jpg");
  6. $new=imagerotate($back, 45, 0);

  7. imagejpeg($new, "./images/hee9.jpg");
  8. ?>
复制代码

图片水平翻转垂直翻转

  1. /**

  2. * 图片水平翻转 垂直翻转
  3. * edit by bbs.it-home.org
  4. */
  5. function turn_y($background, $newfile){
  6. $back=imagecreatefromjpeg($background);

  7. $width=imagesx($back);
  8. $height=imagesy($back);
  9. $new=imagecreatetruecolor($width, $height);
  10. for($x=0; $x imagecopy($new, $back, $width-$x-1, 0, $x, 0, 1, $height);
  11. }
  12. imagejpeg($new, $newfile);
  13. imagedestroy($back);
  14. imagedestroy($new);
  15. }
  16. function turn_x($background, $newfile){
  17. $back=imagecreatefromjpeg($background);
  18. $width=imagesx($back);
  19. $height=imagesy($back);
  20. $new=imagecreatetruecolor($width, $height);
  21. for($y=0; $y imagecopy($new, $back,0, $height-$y-1, 0, $y, $width, 1);
  22. }
  23. imagejpeg($new, $newfile);
  24. imagedestroy($back);
  25. imagedestroy($new);
  26. }
  27. turn_y("./images/hee.jpg", "./images/hee11.jpg");
  28. turn_x("./images/hee.jpg", "./images/hee12.jpg");
  29. ?>
复制代码


sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan
Tentang kita Penafian Sitemap
Laman web PHP Cina:Latihan PHP dalam talian kebajikan awam,Bantu pelajar PHP berkembang dengan cepat!