《PHP學(xué)習(xí):php動態(tài)生成縮略圖并輸出顯示的方法》要點(diǎn):
本文介紹了PHP學(xué)習(xí):php動態(tài)生成縮略圖并輸出顯示的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP編程本文實(shí)例講述了php動態(tài)生成縮略圖并輸出顯示的辦法.分享給大家供大家參考.具體如下:
PHP編程調(diào)用辦法:
PHP編程
<img src="thumbs.php?filename=photo.jpg&width=100&height=100">
PHP編程此代碼可以為大圖片動態(tài)生成縮略圖顯示,圖片在內(nèi)存中生成,不在硬盤生成真實(shí)文件
PHP編程thumbs.php文件如下:
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編程希望本文所述對大家的php程序設(shè)計(jì)有所贊助.
《PHP學(xué)習(xí):php動態(tài)生成縮略圖并輸出顯示的方法》是否對您有啟發(fā),歡迎查看更多與《PHP學(xué)習(xí):php動態(tài)生成縮略圖并輸出顯示的方法》相關(guān)教程,學(xué)精學(xué)透。維易PHP學(xué)院為您提供精彩教程。
轉(zhuǎn)載請注明本頁網(wǎng)址:
http://www.fzlkiss.com/jiaocheng/11007.html