国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

php生成縮略圖代碼

2024-09-04 11:44:26
字體:
來源:轉載
供稿:網友
  1. <?php 
  2. # Constants 
  3. define("IMAGE_BASE"'./'); 
  4. define("MAX_WIDTH", 150); 
  5. define("MAX_HEIGHT", 150); 
  6.  
  7. # Get image locationstr_replace('..'''$_SERVER['QUERY_STRING']); 
  8. $image_file = 't.jpg'
  9. $image_path = IMAGE_BASE . "$image_file"
  10.  
  11. # Load image 
  12. $img = null; 
  13. $ext = strtolower(end(explode('.'$image_path))); 
  14. if ($ext == 'jpg' || $ext == 'jpeg') { 
  15.      $img = imagecreatefromjpeg($image_path); 
  16. else if ($ext == 'png') { 
  17.      $img = @imagecreatefrompng($image_path); 
  18. # Only if your version of GD includes GIF support 
  19. else if ($ext == 'gif') { 
  20.      $img = @imagecreatefrompng($image_path); 
  21.  
  22. # If an image was successfully loaded, test the image for size 
  23. if ($img) { 
  24.  
  25.      # Get image size and scale ratio 
  26.      $width = imagesx($img); 
  27.      $height = imagesy($img); 
  28.      $scale = min(MAX_WIDTH/$width, MAX_HEIGHT/$height); 
  29.  
  30.      # If the image is larger than the max shrink it 
  31.      if ($scale < 1) { 
  32.          $new_width =150; //floor($scale*$width); 
  33.          $new_height =150;// floor($scale*$height); 
  34.  
  35.          # Create a new temporary image 
  36.          $tmp_img = imagecreatetruecolor($new_width$new_height); 
  37.  
  38.          # Copy and resize old image into new image 
  39.          imagecopyresized($tmp_img$img, 0, 0, 0, 0,$new_width$new_height$width$height); 
  40.          imagedestroy($img); 
  41.          $img = $tmp_img
  42.      } 
  43.  
  44. # Create error image if necessary 
  45. if (!$img) { 
  46.      $img = imagecreate(MAX_WIDTH, MAX_HEIGHT); 
  47.      imagecolorallocate($img,0,0,0); 
  48.      $c = imagecolorallocate($img,70,70,70 ); 
  49.      imageline($img,0,0,MAX_WIDTH,MAX_HEIGHT,$c2); 
  50.      imageline($img,MAX_WIDTH,0,0,MAX_HEIGHT,$c2); 
  51. }//開源代碼Vevb.com 
  52.  
  53. # Display the image 
  54. header("Content-type: image/jpeg"); 
  55. imagejpeg($img); 
  56. imagedestroy($img); 
  57. ?> 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 临猗县| 临湘市| 旬阳县| 达拉特旗| 临西县| 石狮市| 永德县| 乐平市| 海口市| 杂多县| 乌兰县| 邵阳市| 武威市| 喀什市| 西宁市| 惠州市| 清河县| 政和县| 游戏| 德保县| 阜宁县| 乾安县| 西充县| 固阳县| 姜堰市| 梅州市| 湟中县| 师宗县| 醴陵市| 旺苍县| 蓝田县| 阿坝| 拜城县| 高要市| 平潭县| 红桥区| 广汉市| 东港市| 大邑县| 盐池县| 沭阳县|