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

首頁 > 開發 > PHP > 正文

php實現在服務器端調整圖片大小的方法

2024-05-04 23:36:15
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了php實現在服務器端調整圖片大小的方法,實例分析了imageResizer與loadimage操作圖片的相關技巧,需要的朋友可以參考下

本文實例講述了php實現在服務器端調整圖片大小的方法。分享給大家供大家參考。具體分析如下:

在服務器端完成圖片大小的調整,會比在瀏覽器的處理有很多的好處。

本文介紹了PHP如何在服務器端調整圖片大小。

代碼包括兩部分:

① imageResizer() is used to process the image

② loadimage() inserts the image url in a simpler format

 

 
  1. <?php 
  2. function imageResizer($url$width$height) { 
  3. header('Content-type: image/jpeg'); 
  4. list($width_orig$height_orig) = getimagesize($url); 
  5. $ratio_orig = $width_orig/$height_orig
  6. if ($width/$height > $ratio_orig) { 
  7. $width = $height*$ratio_orig
  8. else { 
  9. $height = $width/$ratio_orig
  10. // This resamples the image 
  11. $image_p = imagecreatetruecolor($width$height); 
  12. $image = imagecreatefromjpeg($url); 
  13. imagecopyresampled($image_p$image, 0, 0, 0, 0, $width$height$width_orig$height_orig); 
  14. // Output the image 
  15. imagejpeg($image_p, null, 100); 
  16. //works with both POST and GET 
  17. $method = $_SERVER['REQUEST_METHOD']; 
  18. if ($method == 'GET') { 
  19. imageResize($_GET['url'], $_GET['w'], $_GET['h']); 
  20. elseif ($method == 'POST') { 
  21. imageResize($_POST['url'], $_POST['w'], $_POST['h']); 
  22. // makes the process simpler 
  23. function loadImage($url$width$height){ 
  24. echo 'image.php?url=', urlencode($url) , 
  25. '&w=',$width
  26. '&h=',$height
  27. ?> 

用法:

 

 
  1. //Above code would be in a file called image.php. 
  2. //Images would be displayed like this: 
  3. <img src="<?php loadImage('image.jpg', 50, 50) ?>" alt="" /> 

希望本文所述對大家的php程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 龙山县| 台安县| 宝兴县| 彭山县| 玉溪市| 惠来县| 剑河县| 宜兴市| 永和县| 白朗县| 闸北区| 阳曲县| 平遥县| 习水县| 香格里拉县| 株洲市| 定安县| 梁平县| 仁怀市| 华阴市| 望都县| 绥宁县| 乐陵市| 西城区| 红原县| 淅川县| 游戏| 延川县| 汉阴县| 仲巴县| 广昌县| 白水县| 紫云| 炉霍县| 北海市| 正安县| 丽江市| 铁力市| 于田县| 封开县| 靖远县|