程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php動態生成縮略圖並輸出顯示的方法

php動態生成縮略圖並輸出顯示的方法

編輯:關於PHP編程

         下面為你介紹了php動態生成縮略圖並輸出顯示的方法,涉及php操作圖片的相關技巧,非常具有實用價值,需要的朋友可以參考下

      本文實例講述了php動態生成縮略圖並輸出顯示的方法。分享給大家供大家參考。具體如下:

      調用方法:

      ?

    1 <img src="thumbs.php?filename=photo.jpg&width=100&height=100">

      此代碼可以為大圖片動態生成縮略圖顯示,圖片在內存中生成,不在硬盤生成真實文件

      thumbs.php文件如下:

      ?

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 <?php $filename= $_GET['filename']; $width = $_GET['width']; $height = $_GET['height']; $path="http://localhost/images/"; //finish in "/" // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($path.$filename); if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($path.$filename); imagecopyresampled($image_p,$image,0,0,0,0,$width,$height,$width_orig,$height_orig); // Output imagejpeg($image_p, null, 100); // Imagedestroy imagedestroy ($image_p); ?>

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

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved