beta3.0
This commit is contained in:
168
dzz/imageColor/classes/getcolor.php
Normal file
168
dzz/imageColor/classes/getcolor.php
Normal file
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace dzz\imageColor\classes;
|
||||
|
||||
|
||||
use \core as C;
|
||||
use \DB as DB;
|
||||
use \ImagePalette as ImagePalette;
|
||||
|
||||
|
||||
class getColor
|
||||
{
|
||||
public $palette = array(
|
||||
0x111111, 0xFFFFFF, 0x9E9E9E, 0xA48057, 0xFC85B3, 0xFF2727, 0xFFA34B, 0xFFD534, 0x47C595, 0x51C4C4, 0x2B76E7, 0x6D50ED
|
||||
);
|
||||
|
||||
public function run(&$data)
|
||||
{
|
||||
$exts = getglobal('config/getcolorextlimit') ? getglobal('config/getcolorextlimit') : ['jpg', 'jpeg', 'png', 'gif', 'webp', 'pdf'];
|
||||
$data['ext'] = strtolower($data['ext']);
|
||||
if (!$data['ext'] || !in_array($data['ext'], $exts)) {
|
||||
return true;
|
||||
} else {
|
||||
if (strtolower($data['ext']) == 'pdf' && !extension_loaded('imagick')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$setarr = [
|
||||
'rid' => $data['rid'],
|
||||
'appid' => $data['appid'],
|
||||
'ext' => $data['ext']
|
||||
];
|
||||
$isforce = (isset($data['isforce'])) ? 1 : 0;
|
||||
C::t('pichome_imagickrecord')->insert($setarr, $isforce);
|
||||
//dfsockopen(getglobal('localurl') . 'index.php?mod=imageColor&op=index&path=' . dzzencode($data['rid']), 0, '', '', false, '', 0.1);
|
||||
}
|
||||
}
|
||||
|
||||
public function rundata($data)
|
||||
{
|
||||
|
||||
|
||||
//创建缩略图目录
|
||||
if (!is_dir(getglobal('setting/attachdir') . './' . 'pichomethumb/' . $data['appid'])) {
|
||||
dmkdir(getglobal('setting/attachdir') . './' . 'pichomethumb/' . $data['appid'], 0777, false);
|
||||
}
|
||||
$width = getglobal('config/pichomethumbwidth') ? getglobal('config/pichomethumbwidth') : 900;
|
||||
$height = getglobal('config/pichomethumbheight') ? getglobal('config/pichomethumbheight') : 900;
|
||||
//判断是否生成缩略图
|
||||
if (($data['width'] < $width) && ($data['height'] < $height)) {
|
||||
$img = $data['realpath'];
|
||||
//转换缩略图路径
|
||||
$img = str_replace(array('./', '/', '\\'), BS, $img);
|
||||
//更改缩略图生成状态为1
|
||||
C::t('pichome_imagickrecord')->update($data['rid'], array('thumbstatus' => 1));
|
||||
} else {
|
||||
$target = 'pichomethumb/' . $data['appid'] . '/' . md5($data['path']) . '.jpg';
|
||||
$img = $this->createthumb($data['realpath'], $target, $width, $height, 1);
|
||||
|
||||
if ($img) {
|
||||
C::t('pichome_resources')->update($data['rid'], array('hasthumb' => 1));
|
||||
//转换缩略图路径
|
||||
$img = str_replace(array('./', '/', '\\'), BS, $img);
|
||||
|
||||
C::t('pichome_imagickrecord')->update($data['rid'], array('thumbstatus' => 1,'path'=>$img));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (is_file($img)) {
|
||||
|
||||
$lib = extension_loaded('imagick') ? 'imagick' : 'gd';
|
||||
try {
|
||||
$palette = new ImagePalette($img, 1, 10, $lib, $this->palette);
|
||||
$palettes = $palette->palette;
|
||||
} catch (\Exception $e) {
|
||||
runlog('imageColor', $e->getMessage() . ' img=' . $img);
|
||||
}
|
||||
|
||||
if (!is_array($palettes)) {
|
||||
DB::delete('pichome_palette', array('rid' => $data['rid']));
|
||||
|
||||
// return;
|
||||
} else {
|
||||
DB::delete('pichome_palette', array('rid' => $data['rid']));
|
||||
foreach ($palettes as $k => $v) {
|
||||
$color = new \Color($k);
|
||||
$rgbcolor = $color->toRgb();
|
||||
$data = [
|
||||
'rid' => $data['rid'],
|
||||
'color' => $k,
|
||||
'r' => $rgbcolor[0],
|
||||
'g' => $rgbcolor[1],
|
||||
'b' => $rgbcolor[2],
|
||||
'weight' => $v
|
||||
];
|
||||
C::t('pichome_palette')->insert($data);
|
||||
C::t('pichome_imagickrecord')->update($data['rid'], array('colorstatus' => 1));
|
||||
C::t('pichome_resources_attr')->update($data['rid'], array('isget' => 1));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function createthumb($fileuri, $target, $width, $height, $thumbtype = 1)
|
||||
{
|
||||
global $_G;
|
||||
include_once libfile('class/image');
|
||||
$target_attach = $_G['setting']['attachdir'] . './' . $target;
|
||||
$targetpath = dirname($target_attach);
|
||||
dmkdir($targetpath);
|
||||
$image = new \image();
|
||||
//$fileuri = str_replace(DZZ_ROOT,'',$fileuri);
|
||||
try {
|
||||
$thumb = $image->Thumb($fileuri, $target, $width, $height, $thumbtype);
|
||||
} catch (\Exception $e) {
|
||||
$thumb = false;
|
||||
|
||||
}
|
||||
return ($thumb) ? $target_attach : false;
|
||||
}
|
||||
|
||||
function getpdfthumb($data)
|
||||
{
|
||||
|
||||
$width = getglobal('config/pichomethumbwidth') ? getglobal('config/pichomethumbwidth') : 900;
|
||||
$height = getglobal('config/pichomethumbheight') ? getglobal('config/pichomethumbheight') : 900;
|
||||
if (!extension_loaded('imagick')) {
|
||||
return true;
|
||||
}
|
||||
if (!is_dir(getglobal('setting/attachdir') . './' . 'pichomethumb/' . $data['appid'])) {
|
||||
dmkdir(getglobal('setting/attachdir') . './' . 'pichomethumb/' . $data['appid'], 0777, false);
|
||||
}
|
||||
if (!file_exists($data['realpath'])) {
|
||||
return true;
|
||||
}
|
||||
$target = 'pichomethumb/' . $data['appid'] . '/' . md5($data['path']) . '.jpg';
|
||||
$im = new \Imagick();
|
||||
$im->setResolution($width, $height); //设置图像分辨率
|
||||
$im->setCompressionQuality(80); //压缩比
|
||||
try {
|
||||
$im->readImage($data['realpath'] . '[0]'); //设置读取pdf的第一页
|
||||
} catch (\Exception $e) {
|
||||
runlog('pdfthumb', iconv("gbk", 'utf-8', $e->getMessage()));
|
||||
}
|
||||
|
||||
//$im->thumbnailImage(200, 100, true); // 改变图像的大小
|
||||
$im->scaleImage($width, $height, true); //缩放大小图像
|
||||
$filename = getglobal('setting/attachdir') . './' . $target;
|
||||
|
||||
if ($im->writeImage($filename) == true) {
|
||||
$imginfo = @getimagesize($filename);
|
||||
$resourcesarr = [
|
||||
'width' => $imginfo[0] ? $imginfo[0]:0,
|
||||
'height' =>$imginfo[1] ? $imginfo[1]:0
|
||||
];
|
||||
C::t('pichome_resources')->update($data['rid'],$resourcesarr);
|
||||
C::t('pichome_imagickrecord')->update($data['rid'], array('thumbstatus' => 1,'colorstatus'=>1,'path'=>$filename));
|
||||
C::t('pichome_resources')->update($data['rid'], array('hasthumb' => 1));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
86
dzz/imageColor/index.php
Normal file
86
dzz/imageColor/index.php
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
ignore_user_abort(true);
|
||||
if (!defined('IN_OAOOA')) {
|
||||
exit('Access Denied');
|
||||
}
|
||||
@set_time_limit(0);
|
||||
ini_set('memory_limit', -1);
|
||||
@ini_set('max_execution_time', 0);
|
||||
$appids = [];
|
||||
foreach(DB::fetch_all("select appid from %t where `type` = %d and getinfo = %d",array('pichome_vapp',1,1)) as $v){
|
||||
$appids[] = $v['appid'];
|
||||
}
|
||||
if(empty($appids)){
|
||||
exit('success');
|
||||
}
|
||||
$locked = true;
|
||||
for($i=0;$i<1;$i++){
|
||||
$processname = 'DZZ_LOCK_PICHOMEGETCOLOR'.$i;
|
||||
if (!dzz_process::islocked($processname, 60*60)) {
|
||||
$locked=false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
$processname = 'DZZ_LOCK_PICHOMEGETCOLOR'.$i;
|
||||
$limit = 10;
|
||||
$start=$i*$limit;
|
||||
if (!dzz_process::islocked($processname, 60*60)) {
|
||||
$locked=false;
|
||||
}
|
||||
if ($locked) {
|
||||
exit(json_encode( array('error'=>'进程已被锁定请稍后再试')));
|
||||
}
|
||||
use dzz\imageColor\classes\getcolor as getcolor;
|
||||
|
||||
$getcolor =new getcolor;
|
||||
|
||||
foreach(DB::fetch_all("select * from %t where thumbstatus = 0 or colorstatus = 0 and appid in(%n)
|
||||
order by thumbdonum asc,colordonum asc limit $start,$limit",array('pichome_imagickrecord',$appids)) as $v){
|
||||
$processname1 = 'PICHOMEGETCOLOR_'.$v['rid'];
|
||||
if (dzz_process::islocked($processname1, 60*5)) {
|
||||
continue;
|
||||
}
|
||||
$data = C::t('pichome_resources')->fetch_data_by_rid($v['rid']);
|
||||
|
||||
if(empty($data)){
|
||||
C::t('pichome_imagickrecord')->delete($v['rid']);
|
||||
dzz_process::unlock($processname1);
|
||||
continue;
|
||||
}else{
|
||||
//如果缩略图执行次数大于三次,直接赋值为1,不再尝试生成
|
||||
if($v['thumbdonum'] > 3 && $v['thumbstatus'] == 0){
|
||||
$v['thumbstatus'] = 1;
|
||||
//如果当前文件为pdf,直接赋值颜色生成为1
|
||||
if(strtolower($v['ext']) == 'pdf'){
|
||||
$v['colorstatus'] = 1;
|
||||
C::t('pichome_imagickrecord')->update($v['rid'],array('thumbstatus'=>1,'colorstatus'=>1));
|
||||
}
|
||||
}
|
||||
if($v['colordonum'] > 3 && $v['colorstatus'] == 0){
|
||||
$v['colorstatus'] = 1;
|
||||
C::t('pichome_imagickrecord')->update($v['rid'],array('colorstatus'=>1));
|
||||
}
|
||||
//如果颜色和缩略图标记为已生成,标记该文件信息状态为已获取
|
||||
if($v['thumbstatus'] == 1 && $v['colorstatus'] == 1){
|
||||
C::t('pichome_resources_attr')->update($v['rid'],array('isget'=>1));
|
||||
dzz_process::unlock($processname1);
|
||||
continue;
|
||||
}
|
||||
// $data['colorstatus'] = $v['colorstatus'];
|
||||
//$data['thumbstatus'] = $v['thumbstatus'];
|
||||
if(strtolower($data['ext']) == 'pdf'){
|
||||
DB::query("update %t set thumbdonum=thumbdonum+%d where rid = %s ", array('pichome_imagickrecord', 1, $data['rid']));
|
||||
$getcolor->getpdfthumb($data);
|
||||
}else{
|
||||
if(!$v['colorstatus']) DB::query("update %t set colordonum=colordonum+%d where rid = %s ", array('pichome_imagickrecord', 1, $data['rid']));
|
||||
if(!$v['thumbstatus']) DB::query("update %t set thumbdonum=thumbdonum+%d where rid = %s ", array('pichome_imagickrecord', 1, $data['rid']));
|
||||
$getcolor->rundata($data);
|
||||
}
|
||||
}
|
||||
dzz_process::unlock($processname1);
|
||||
}
|
||||
dzz_process::unlock($processname);
|
||||
if(DB::result_first("select count(*) from %t where thumbstatus = 0 or colorstatus = 0 ",array('pichome_imagickrecord'))){
|
||||
dfsockopen(getglobal('localurl') . 'index.php?mod=imageColor&op=index', 0, '', '', false, '', 0.1);
|
||||
}
|
||||
exit('success'.$i);
|
||||
Reference in New Issue
Block a user