生活随笔
收集整理的這篇文章主要介紹了
PHP 实现缩略图
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
PHP 實現(xiàn)縮略圖
<?php
header(
"Content-type: image/png");
function resize_image($filename, $tmpname, $xmax, $ymax)
{ $ext = explode(
".",
$filename);
$ext =
$ext[count(
$ext)-
1];
if(
$ext ==
"jpg" ||
$ext ==
"jpeg")
$im = imagecreatefromjpeg(
$tmpname);
elseif(
$ext ==
"png")
$im = imagecreatefrompng(
$tmpname);
elseif(
$ext ==
"gif")
$im = imagecreatefromgif(
$tmpname);
$x = imagesx(
$im);
$y = imagesy(
$im);
if(
$x <=
$xmax &&
$y <=
$ymax)
return $im;
if(
$x >=
$y) {
$newx =
$xmax;
$newy =
$newx *
$y /
$x; }
else {
$newy =
$ymax;
$newx =
$x /
$y *
$newy; }
$im2 = imagecreatetruecolor(
$newx,
$newy); imagecopyresized(
$im2,
$im,
0,
0,
0,
0, floor(
$newx), floor(
$newy),
$x,
$y);
return $im2;
}
imagejpeg(resize_image(
'nriven.jpg',
'riven.jpg',
300,
300));
?>
總結(jié)
以上是生活随笔為你收集整理的PHP 实现缩略图的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。