php動態(tài)生成縮略圖并輸出顯示的方法
更新時間:2015年04月20日 09:07:29 作者:不吃皮蛋
這篇文章主要介紹了php動態(tài)生成縮略圖并輸出顯示的方法,涉及php操作圖片的相關(guān)技巧,非常具有實用價值,需要的朋友可以參考下
本文實例講述了php動態(tài)生成縮略圖并輸出顯示的方法。分享給大家供大家參考。具體如下:
調(diào)用方法:
<img src="thumbs.php?filename=photo.jpg&width=100&height=100">
此代碼可以為大圖片動態(tài)生成縮略圖顯示,圖片在內(nèi)存中生成,不在硬盤生成真實文件
thumbs.php文件如下:
<?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程序設(shè)計有所幫助。
相關(guān)文章
PHP中Static(靜態(tài))關(guān)鍵字功能與用法實例分析
這篇文章主要介紹了PHP中Static(靜態(tài))關(guān)鍵字功能與用法,結(jié)合實例形式分析了Static關(guān)鍵字功能、以及靜態(tài)屬性、靜態(tài)變量等相關(guān)使用技巧,需要的朋友可以參考下2019-04-04
php allow_url_include的應(yīng)用和解釋
PHP常常因為它可能允許URLS被導(dǎo)入和執(zhí)行語句被人們指責(zé)。事實上,這件事情并不是很讓人感到驚奇,因為這是導(dǎo)致稱為Remote URL Include vulnerabilities的php應(yīng)用程序漏洞的最重要的原因之一。2010-04-04
php serialize()與unserialize() 不完全研究
這篇文章主要介紹了php serialize()與unserialize() 的一些區(qū)別,需要的朋友可以參考下2017-11-11

