《PHP應用:PHP實現(xiàn)原比例生成縮略圖的方法》要點:
本文介紹了PHP應用:PHP實現(xiàn)原比例生成縮略圖的方法,希望對您有用。如果有疑問,可以聯(lián)系我們。
PHP學習本文實例講述了PHP實現(xiàn)原比例生成縮略圖的辦法.分享給大家供大家參考,具體如下:
PHP學習
<?php
$image = "jiequ.jpg"; // 原圖
$imgstream = file_get_contents($image);
$im = imagecreatefromstring($imgstream);
$x = imagesx($im);//獲取圖片的寬
$y = imagesy($im);//獲取圖片的高
// 縮略后的大小
$xx = 140;
$yy = 200;
if($x>$y){
//圖片寬大于高
$sx = abs(($y-$x)/2);
$sy = 0;
$thumbw = $y;
$thumbh = $y;
} else {
//圖片高大于等于寬
$sy = abs(($x-$y)/2.5);
$sx = 0;
$thumbw = $x;
$thumbh = $x;
}
if(function_exists("imagecreatetruecolor")) {
$dim = imagecreatetruecolor($yy, $xx); // 創(chuàng)建目標圖gd2
} else {
$dim = imagecreate($yy, $xx); // 創(chuàng)建目標圖gd1
}
imageCopyreSampled ($dim,$im,0,0,$sx,$sy,$yy,$xx,$thumbw,$thumbh);
header ("Content-type: image/jpeg");
imagejpeg ($dim, false, 100);
?>
PHP學習更多關于PHP相關內(nèi)容感興趣的讀者可查看本站專題:《PHP圖形與圖片操作技巧匯總》、《PHP基本語法入門教程》及《php常用函數(shù)與技巧總結》
PHP學習希望本文所述對大家PHP程序設計有所贊助.
歡迎參與《PHP應用:PHP實現(xiàn)原比例生成縮略圖的方法》討論,分享您的想法,維易PHP學院為您提供專業(yè)教程。
轉載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/7602.html