php 缩略图函数
2010-01-15 15:56
274 查看
function getThumbs($filename,$savepath,$d_w,$d_h,$b,$img_name)
{
if($b)
{
$photourl = $savepath."/".$img_name;
}else
{
$photourl = $savepath;
}
$width = $d_w;
$height= $d_h;
list($width_orig, $height_orig,$image_type) = getimagesize($filename);
$extends = $image_type == 1 ? "gif" : "jpg";
$x = 0;$y = 0;
if($d_w==$d_h)
{
if ($width && ($width_orig < $height_orig))
{
$height = ($width / $width_orig) * $height_orig;
$y = round(($height-$d_h)/2);
} else
{
$width = ($height / $height_orig) * $width_orig;
$x = round(($width-$d_w)/2);
}
}else
{
if($d_h>$d_w)
{
$width = ($height / $height_orig) * $width_orig;
// $x = round(($width-$d_w)/2);
}else
{
$height = ($width / $width_orig) * $height_orig;
// $y = round(($height-$d_h)/2);
}
}
// Resample
$image_p = imagecreatetruecolor($d_w, $d_h);
$image = $image_type==1 ? imagecreatefromgif($filename) : imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, $x, $y, $width, $height, $width_orig, $height_orig);
$image_type==1 ? imagegif($image_p,$photourl,100) : imagejpeg($image_p, $photourl, 100);
return preg_replace('/.*upload/','/upload',$photourl);
}
{
if($b)
{
$photourl = $savepath."/".$img_name;
}else
{
$photourl = $savepath;
}
$width = $d_w;
$height= $d_h;
list($width_orig, $height_orig,$image_type) = getimagesize($filename);
$extends = $image_type == 1 ? "gif" : "jpg";
$x = 0;$y = 0;
if($d_w==$d_h)
{
if ($width && ($width_orig < $height_orig))
{
$height = ($width / $width_orig) * $height_orig;
$y = round(($height-$d_h)/2);
} else
{
$width = ($height / $height_orig) * $width_orig;
$x = round(($width-$d_w)/2);
}
}else
{
if($d_h>$d_w)
{
$width = ($height / $height_orig) * $width_orig;
// $x = round(($width-$d_w)/2);
}else
{
$height = ($width / $width_orig) * $height_orig;
// $y = round(($height-$d_h)/2);
}
}
// Resample
$image_p = imagecreatetruecolor($d_w, $d_h);
$image = $image_type==1 ? imagecreatefromgif($filename) : imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, $x, $y, $width, $height, $width_orig, $height_orig);
$image_type==1 ? imagegif($image_p,$photourl,100) : imagejpeg($image_p, $photourl, 100);
return preg_replace('/.*upload/','/upload',$photourl);
}
相关文章推荐
- php生成缩略图函数
- PHP图片处理函数:水印、缩略图
- PHP实现生成透明背景的PNG缩略图函数分享
- PHP 生成图片缩略图函数
- php 缩略图实现函数代码
- 兼容性最强的PHP生成缩略图的函数代码(修改版)
- PHP生成缩略图函数
- php 缩略图函数
- PHP创建图片缩略图函数
- PHP自适应宽高度等比例缩略图函数 (无裁切)
- 强大的PHP生成缩略图函数
- php 为图片加水印函数和缩略图的函数代码
- php上传图片自动生成缩略图方法函数
- windows环境下FFmpeg配置—— php生成视频缩略图,转换视频函数
- php 缩略图实现函数代码
- 一个简单的PHP生成缩略图函数
- 兼容性最强的PHP生成缩略图的函数代码(修改版)
- php图片处理:加水印、缩略图的实现(自定义函数:watermark、thumbnail)
- PHP中imagecopyresampled函数创建缩略图参数详解
- PHP图片等比例缩放生成缩略图函数分享