主题: KindEditor上传大图片自动生成小图片
作者: wodingg, 发布日期: 2012-04-10 23:00:28, 浏览数: 6175

本文以 upload_json.php (在php文件夹里面) 为基础增加几个代码。

 

请在第95行位置增加如下代码。

 

/*
截取图片大小
*/
$filename = $file_path;

// Set a maximum height and width
$width = 800;
$height = 600;

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($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($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p, $filename, 100);

其实很简单,就是引用了PHP的说明文档,修改几个参数,我现在正在想办,在上传图片的弹窗中增加一个“设置成封面”的按钮,这样方便一些网站使用焦点图播放,但还没解决,有解决的朋友共享一下吧。

 

QQ:29040089

发表新帖 发表回复