software
574 days ago
4images 补丁
视频文件速度补丁
上面的修改只能在首页有效,在制作缩图时仍然比较慢,所以直接重新包装getimagesize函数.
#!/bin/sh
tmp=/tmp/searchreplace
sed 's/getimagesize/wz_getimagesize/g' $1 >$tmp
mv $tmp $1
将所有getimagesize替换为wz_getimagesize
find photo/ -name *.php -exec grep -H getimagesize {} \;
需要替换的文件有:
./member.php
./admin/resizer.php
./admin/admin_functions.php
./admin/thumbnailer.php
./includes/functions.php
./includes/image_utils.php
./includes/upload.php
./includes/captcha_utils.php
在./includes/functions.php中添加
function wz_getimagesize($src,&$info)
{
return (filesize($src)<5000000 && !wz_is_mov($src))? getimagesize($src,$info):0;
}
视频文件缩略图补丁
对电影格式提供生成所略图支持,上传后自动生成.jpg的所略图,支持ftp上传后,批量生成.参考Web1.
在inclues/functions.php里添加:
function wz_is_mov($src)
{
return in_array(get_file_extension($src), array("mpg", "mpeg", "avi","asf","wmv","flv","swf","mov"))? 1:0;
}
function Generate_VideoThumb($src, $dest) {
global $convert_options;
// $command = "/usr/bin/mplayer \"".$src."\" -ss 00:00:05 -nosound -vo jpeg:smooth=100 -vop scale=200:150 -frames 1";
$command = "/usr/bin/mplayer \"".$src."\" -nosound -vo jpeg:smooth=100 -vop scale=200:150 -frames 1";
system($command);
rename("00000001.jpg",$dest);
return (file_exists($dest)) ? 1 : 0;
}
在“设置界面“也要添加上述后缀,否则“搜索新文件时查找不到.
-ss 00:00:05对某些视频文件不能生成.jpg,设置为00:00:00正常.
修改:includes/image_utils.php
function create_thumbnail($src, $dest, $quality, $dimension, $resize_type) {
global $convert_options;
if (file_exists($dest)) {
@unlink($dest);
}
$image_info = (defined("IN_CP")) ? wz_getimagesize($src) : @wz_getimagesize($src);
if (!$image_info) {
//**modified from here
//return false;
if(wz_is_mov($src) && Generate_VideoThumb($src, $dest)) {
echo "[".$src."|".$dest."]";
return true;
}
echo "[".$src."|".$dest."]";
//**modified to here
return false;
}
$width_height = get_width_height($dimension, $image_info[0], $image_info[1], $resize_type);
$resize_handle = "resize_image_".$convert_options['convert_tool'];
if ($resize_handle($src, $dest, $quality, $width_height['width'], $width_height['height'], $image_info)) {
@chmod($dest, CHMOD_FILES);
return true;
}
else {
return false;
}
}
修改member.php
// Uplad thumb file
$new_thumb_name = "";
if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
$new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, get_basefile($new_name));
if (!$new_thumb_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
@unlink(MEDIA_TEMP_PATH."/".$new_name);
$uploaderror = 1;
}
}
elseif (check_remote_thumb($remote_thumb_file)) {
$new_thumb_name = $remote_thumb_file;
}
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) {
if ($direct_upload) {
$src = MEDIA_PATH."/".$cat_id."/".$new_name;
$dest = THUMB_PATH."/".$cat_id."/".$new_name;
}
else {
$src = MEDIA_TEMP_PATH."/".$new_name;
$dest = THUMB_TEMP_PATH."/".$new_name;
}
$do_create = 0;
if ($image_info = @wz_getimagesize($src)) {
if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
$do_create = 1;
}
}
if ($do_create) {
require(ROOT_PATH.'includes/image_utils.php');
$convert_options = init_convert_options();
if (!$convert_options['convert_error']) {
$dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
$resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
$quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;
if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
$new_thumb_name = $new_name;
}
}
}
//**********add from here
else if (wz_is_mov($new_name)) {
if (Generate_VideoThumb($src, $dest.".jpg"))
$new_thumb_name = $new_name.".jpg";
}
//**********add to here
修改admin/thumbnailer.php
@set_time_limit(90);
//****************added from here
$wz_dst=$image_cache[$key]['image_media_file'];
if (wz_is_mov(MEDIA_PATH."/".$image_cache[$key]['cat_id']."/".$image_cache[$key]['image_media_file'])) $wz_dst=$wz_dst.".jpg";
//*****************added to here
//if (create_thumbnail(MEDIA_PATH."/".$image_cache[$key]['cat_id']."/".$image_cache[$key]['image_media_file'], THUMB_PATH."/".$image_cache[$key]['cat_id']."/".$image_cache[$key]['image_media_file'], $quality, $dimension, $resize_type)) {
if (create_thumbnail(MEDIA_PATH."/".$image_cache[$key]['cat_id']."/".$image_cache[$key]['image_media_file'], THUMB_PATH."/".$image_cache[$key]['cat_id']."/".$wz_dst, $quality, $dimension, $resize_type)) {
$sql = "UPDATE ".IMAGES_TABLE."
SET image_thumb_file = '".addslashes($wz_dst)."'
WHERE image_id = $key";
//******************************************
$site_db->query($sql);
echo "<br /> <b>".$lang['creating_thumbnail_success']."</b><p>";
}
else {
echo "<br /> <b class=\"marktext\">".$lang['creating_thumbnail_error']."</b><p>";