/**
  * 图片加水印 
  * @param type $source 原图文件名。
  * @param type $water 水印图片文件名
  * @param type $savename 要保存的图片名,如果留空则用source
  * @param type $alpha  水印图片的alpha值,默认为80,范围为0~100
  * @param type $waterPos 水印位置。
  * @param type $quality jpg图片质量
  */
 public function water($source, $water = null, $savename = null, $alpha = null, $waterPos = null, $quality = null)
 {
     import("Image");
     //设置默认水印
     if ($water == '') {
         $water = SITE_PATH . $this->Config['watermarkimg'];
     }
     //图像信息
     $sInfo = Image::getImageInfo($source);
     //如果图片小于系统设置,不进行水印添加
     if ($sInfo["width"] < (int) $this->Config['watermarkminwidth'] || $sInfo['height'] < (int) $this->Config['watermarkminheight']) {
         return false;
     }
     //水印位置
     if (empty($waterPos)) {
         $waterPos = (int) $this->Config['watermarkpos'];
     }
     //水印透明度
     if (empty($alpha)) {
         $alpha = (int) $this->Config['watermarkpct'];
     }
     //jpg图片质量
     if (empty($quality)) {
         $quality = (int) $this->Config['watermarkquality'];
     }
     return Image::water($source, $water, $savename, $alpha, $waterPos, $quality);
 }
 private function save($file)
 {
     $filename = $file['savepath'] . $file['savename'];
     if (!$this->uploadReplace && is_file($filename)) {
         $this->error = LParse(L('_FILE_REPLACE_ERROR_'), array($filename));
         return false;
     }
     if (!move_uploaded_file($file['tmp_name'], auto_charset($filename, 'utf-8', 'gbk'))) {
         $this->error = L('_FILE_MOVE_ERROR_');
         return false;
     }
     if ($this->thumb) {
         import("ORG.Util.Image");
         $image = Image::getImageInfo($filename);
         if (false !== $image) {
             $thumbWidth = explode(',', $this->thumbMaxWidth);
             $thumbHeight = explode(',', $this->thumbMaxHeight);
             $thumbPrefix = explode(',', $this->thumbPrefix);
             $thumbSuffix = explode(',', $this->thumbSuffix);
             $thumbPath = $this->thumbPath ? $this->thumbPath : $file['savepath'];
             for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) {
                 $thumbname = $thumbPath . $thumbPrefix[$i] . substr($file['savename'], 0, strrpos($file['savename'], '.')) . $thumbSuffix[$i] . '.' . $file['extension'];
                 Image::thumb($filename, '', $thumbname, $thumbWidth[$i], $thumbHeight[$i], true);
             }
         }
     }
     if ($this->zipImages) {
         // TODO Image compression package on-line decompression
     }
     return true;
 }
Example #3
0
function resizeImage()
{
    //lay duong dan file duoc request
    $request = $_SERVER['REQUEST_URI'];
    //lay ten file
    $tmp_request = explode('/', $request);
    $case = count($tmp_request);
    $image_name = $tmp_request[$case - 1];
    //type resize
    $resize_type = $tmp_request[$case - 2];
    //echo $image_name;
    $resource_img = get_picture_dir($image_name) . '/' . $image_name;
    $resource_img = '..' . $resource_img;
    if (!file_exists($resource_img)) {
        error_404_document();
    }
    //echo file_get_contents($resource_img);exit();
    $images = new Image($resource_img);
    $imageinfo = $images->getImageInfo();
    if ($imageinfo['height'] == null || $imageinfo['height'] == 0) {
        error_404_document();
    }
    //kich thuoc resize
    $array_resize = array('large' => array(480, 360), 'medium' => array(240, 180), 'medium2' => array(145, 95), 'small' => array(106, 80), 'thumb' => array(50, 50), 'mobile' => array(640, 400), 'mobile_medium' => array(320, 200), 'mobile_small' => array(120, 75), 'mobile_low' => array(640, 400, 30), 'mobile_medium_low' => array(320, 200, 30), 'mobile_small_low' => array(120, 75, 30));
    if (!isset($array_resize[$resize_type])) {
        error_404_document();
    }
    //image name file no extension
    $filesavename = explode('.', $image_name);
    $count3 = count($filesavename);
    if ($count3 > 1) {
        unset($filesavename[$count3 - 1]);
    }
    $filesavename = implode('.', $filesavename);
    $pathsave = '..' . get_picture_dir($image_name, $resize_type);
    //nếu thư mục ảnh không tồn tại thì tạo mới
    if (!file_exists($pathsave)) {
        mkdir($pathsave, 0755, 1);
    }
    //echo $pathsave;die();
    //kich thuoc resize ok -> tao file voi kich thuoc phu hop
    $r_width = $array_resize[$resize_type][0];
    $r_height = $array_resize[$resize_type][1];
    if (isset($array_resize[$resize_type][2])) {
        $r_quality = $array_resize[$resize_type][2];
    } else {
        $r_quality = 100;
    }
    if ($resize_type == 'organic') {
        $images->resize($r_width, $r_height, 'fit', 'c', 'c', $r_quality);
    } else {
        $images->resize($r_width, $r_height, 'crop', 'c', 'c', $r_quality);
    }
    $images->save($filesavename, $pathsave);
    header("HTTP/1.0 200 OK");
    $images->display();
}
Example #4
0
 /**
  * 显示服务器图像文件 支持URL方式
  * @param string $imgFile	图像文件名
  * @param string $text		文字字符串
  * @param string $width		图像宽度
  * @param string $height	图像高度
  * @return void
  */
 public static function showImg($imgFile, $text = '', $width = 80, $height = 30)
 {
     //获取图像文件信息
     $info = Image::getImageInfo($imgFile);
     if ($info !== false) {
         //修改读取bmp图片
         $createFun = str_replace('/', 'createfrom', $info['mime']);
         if (strrpos($info['mime'], 'bmp')) {
             $strImg = "";
             $strImg = file_get_contents($imgFile);
             header("Content-type: " . $info['mime']);
             echo $strImg;
             return;
         }
         $im = $createFun($imgFile);
         if ($im) {
             $ImageFun = str_replace('/', '', $info['mime']);
             if (!empty($text)) {
                 $tc = imagecolorallocate($im, 0, 0, 0);
                 imagestring($im, 3, 5, 5, $text, $tc);
             }
             if ($info['type'] == 'png' || $info['type'] == 'gif') {
                 imagealphablending($im, false);
                 //取消默认的混色模式
                 imagesavealpha($im, true);
                 //设定保存完整的 alpha 通道信息
             }
             header("Content-type: " . $info['mime']);
             $ImageFun($im);
             imagedestroy($im);
             return;
         }
     }
     //获取或者创建图像文件失败则生成空白PNG图片
     $im = imagecreatetruecolor($width, $height);
     $bgc = imagecolorallocate($im, 255, 255, 255);
     $tc = imagecolorallocate($im, 0, 0, 0);
     imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
     imagestring($im, 4, 5, 5, "NO PIC", $tc);
     Image::output($im);
     return;
 }
/**
*
* @param $origin_path 原始物理图片地址
* @param array $sizes 缩略图大小信息 为空则取后台设置
	 	可生成多个缩略图
		数组 参数1 为宽度,
			 参数2为高度,
			 参数3为处理方式:0(缩放,默认),1(剪裁),
			 参数4为是否水印 默认为 0(不生成水印)
	 	array(
			array(300,300,0,0),
			array(100,100,0,0),
			...
		),
* @param $path 存储的路径
* @param $file_name 保存的文件名
* @param $del_temp 是否删除临时文件
* @param $id 关联编号,将根据编号生成目录
*
* 返回 复制成功的信息,如为false则复制失败
* array(
* 	'path'	=>	xxx  //物理路径
*  'url'	=>	xxx  //相对路径
* );
*
* by fzmatthew
*/
function copyImage($origin_path, $sizes = array(), $path = 'share', $del_temp = true, $id = 0)
{
    global $_FANWE;
    static $size_setting = NULL, $image = NULL;
    if ($image === NULL) {
        include_once fimport('class/image');
        $image = new Image();
    }
    if ($path == 'temp') {
        $dir = './public/upload/temp/' . fToDate(NULL, 'Y/m/d/H');
    } else {
        if ($id > 0) {
            $dir = './public/upload/' . $path . '/' . getDirsById($id);
        } else {
            $dir = './public/upload/' . $path . '/' . fToDate(NULL, 'Y/m/d');
        }
    }
    makeDir(FANWE_ROOT . $dir);
    $file_name = md5(microtime(true)) . random('6') . '.jpg';
    $file_path = FANWE_ROOT . $dir . "/" . $file_name;
    $bln = false;
    if (file_exists($origin_path) && @copy($origin_path, $file_path)) {
        $bln = true;
    } else {
        $data = getUrlContent($origin_path);
        if (!empty($data) && @file_put_contents($file_path, $data) > 0) {
            $bln = true;
        }
    }
    if ($bln) {
        $info = $image->getImageInfo($file_path);
        if ($info['type'] != 'jpg' && $info['type'] != 'jpeg') {
            if (!$image->convertType($file_path, $file_path)) {
                return false;
            }
        }
        $water_image = $_FANWE['setting']['water_image'];
        if (!empty($water_image)) {
            $water_image = FANWE_ROOT . $water_image;
        }
        $water_mark = intval($_FANWE['setting']['water_mark']);
        $alpha = intval($_FANWE['setting']['water_alpha']);
        $place = intval($_FANWE['setting']['water_position']);
        if ($sizes !== false && empty($sizes)) {
            if ($size_setting === NULL) {
                if (!isset($_FANWE['cache']['image_sizes'])) {
                    FanweService::instance()->cache->loadCache('image_sizes');
                }
                $size_setting = $_FANWE['cache']['image_sizes'];
            }
            $sizes = $size_setting;
        }
        foreach ($sizes as $size) {
            if ($size[0] > 0 || $size[1] > 0) {
                $thumb_bln = false;
                $thumb_type = isset($size[2]) ? intval($size[2]) : 0;
                if ($thumb = $image->thumb($file_path, $size[0], $size[1], $thumb_type)) {
                    if (isset($size[3]) && intval($size[3]) > 0) {
                        $image->water($thumb['path'], $water_image, $alpha, $place);
                    }
                }
            }
        }
        if ($del_temp) {
            @unlink($origin_path);
        }
        return array('path' => $file_path, 'url' => $dir . "/" . $file_name, 'width' => $info[0], 'height' => $info[1]);
    } else {
        return false;
    }
}
 /**
  * 用于图片附件上传加水印回调方法
  * @param type $_this
  * @param type $fileInfo
  * @param type $params 
  */
 public static function water($_this, $fileInfo, $params)
 {
     //网站拍照
     $config = cache('Config');
     //是否开启水印
     if (empty($config['watermarkenable'])) {
         return false;
     }
     //水印文件
     $water = SITE_PATH . $config['watermarkimg'];
     //水印位置
     $waterPos = (int) $config['watermarkpos'];
     //水印透明度
     $alpha = (int) $config['watermarkpct'];
     //jpg图片质量
     $quality = (int) $config['watermarkquality'];
     foreach ($fileInfo as $file) {
         //原图文件
         $source = $file['savepath'] . $file['savename'];
         //图像信息
         $sInfo = \Image::getImageInfo($source);
         //如果图片小于系统设置,不进行水印添加
         if ($sInfo["width"] < (int) $config['watermarkminwidth'] || $sInfo['height'] < (int) $config['watermarkminheight']) {
             continue;
         }
         \Image::water($source, $water, $source, $alpha, $waterPos, $quality);
     }
 }
Example #7
0
 public static function ResizeWithCenterCrop($image, $dir, $filename, $target_w, $target_h)
 {
     list($curr_w, $curr_h, $type, $attr) = Image::getImageInfo($image);
     $ext = 'jpg';
     switch ($type) {
         // create image
         case IMAGETYPE_JPEG:
             $ext = 'jpg';
             break;
         case IMAGETYPE_PNG:
             $ext = 'png';
             break;
         case IMAGETYPE_GIF:
             $ext = 'gif';
             break;
         case 'image/svg+xml':
             $ext = 'svg';
             break;
         default:
             return false;
     }
     $scale_h = $target_h / $curr_h;
     $scale_w = $target_w / $curr_w;
     $factor_x = $curr_w / $target_w;
     $factor_y = $curr_h / $target_h;
     if ($factor_x > $factor_y) {
         $factor = $factor_y;
     } else {
         $factor = $factor_x;
     }
     $up_w = ceil($target_w * $factor);
     $up_h = ceil($target_h * $factor);
     $x_start = ceil(($curr_w - $up_w) / 2);
     $y_start = ceil(($curr_h - $up_h) / 2);
     switch ($type) {
         // create image
         case IMAGETYPE_JPEG:
             $n_img = imagecreatefromjpeg($image);
             break;
         case IMAGETYPE_PNG:
             $n_img = imagecreatefrompng($image);
             break;
         case IMAGETYPE_GIF:
             $n_img = imagecreatefromgif($image);
             break;
         case 'image/svg+xml':
             break;
         default:
             return false;
     }
     $dst_img = ImageCreateTrueColor($target_w, $target_h);
     switch ($type) {
         // fix for transparency issues
         case IMAGETYPE_PNG:
             imagealphablending($dst_img, true);
             imagesavealpha($dst_img, true);
             $transparent_color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
             imagefill($dst_img, 0, 0, $transparent_color);
             break;
         case IMAGETYPE_GIF:
             $transparency_index = imagecolortransparent($dst_img);
             if ($transparency_index >= 0) {
                 $transparent_color = imagecolorsforindex($dst_img, $transparency_index);
                 $transparency_index = imagecolorallocate($dst_img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
                 imagefill($dst_img, 0, 0, $transparency_index);
                 imagecolortransparent($dst_img, $transparency_index);
             }
             break;
         default:
             break;
     }
     // (for testing) die('curr_w='.$curr_w.' curr_h='.$curr_h.' x_start='.$x_start.' y_start='.$y_start.' target_w='.$target_w.' target_h='.$target_h.' up_w='.$up_w.' up_h='.$up_h);
     if ($type != 'image/svg+xml') {
         imagecopyresampled($dst_img, $n_img, 0, 0, $x_start, $y_start, $target_w, $target_h, $up_w, $up_h);
     }
     //return $dst_img;
     $full = $dir . $filename;
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     switch ($ext) {
         case 'jpg':
             imagejpeg($dst_img, $full, 100);
             $size = filesize($full);
             return $size;
             break;
         case 'png':
             imagepng($dst_img, $full);
             $size = filesize($full);
             return $size;
             break;
         case 'gif':
             imagegif($dst_img, $full);
             $size = filesize($full);
             return $size;
             break;
         case 'svg':
             copy($image, $full);
             // we just copy it, SVG is vectorized it scales directly in browser
             $size = filesize($full);
             break;
         default:
             return 0;
     }
 }
 public function uploadImg()
 {
     import('ORG.Net.UploadFile');
     import('ORG.Util.Image');
     $where['id'] = array('in', array('1', '2', '3', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '48', '52', '53'));
     $setInfo = $this->uploadSet->where($where)->select();
     $imgAllowExts = explode(',', $setInfo[2]['value']);
     $thumbMax = explode('x', $setInfo[5]['value']);
     $imageMax = explode('x', $setInfo[4]['value']);
     $bthumbMax = explode('x', $setInfo[14]['value']);
     $sthumbMax = explode('x', $setInfo[15]['value']);
     if (!file_exists('./' . $setInfo[0]['value'])) {
         mkdir('./' . $setInfo[0]['value']);
     }
     $savepath = './' . $setInfo[0]['value'];
     if ('1' == $setInfo[1]['value']) {
         $savepath = $savepath . '/' . date('Ymd') . '/';
     } else {
         if (!file_exists($savepath . '/' . date('Ym'))) {
             mkdir($savepath . '/' . date('Ym'));
         }
         $savepath = $savepath . '/' . date('Ym') . '/' . date('d') . '/';
     }
     if (!file_exists($savepath)) {
         mkdir($savepath);
     }
     $config = array('maxSize' => $setInfo[3]['value'] * 1024, 'supportMulti' => true, 'allowExts' => $imgAllowExts, 'thumb' => true, 'thumbMaxWidth' => $thumbMax[0], 'thumbMaxHeight' => $thumbMax[1], 'thumbPrefix' => 'thumb_', 'thumbSuffix' => '', 'thumbPath' => $savepath, 'thumbFile' => '', 'thumbExt' => '', 'thumbRemoveOrigin' => false, 'zipImages' => false, 'autoSub' => false, 'subType' => 'hash', 'dateFormat' => 'Ymd', 'hashLevel' => 1, 'savePath' => $savepath, 'autoCheck' => true, 'uploadReplace' => false, 'saveRule' => 'uniqid', 'hashType' => 'md5_file');
     $upload = new UploadFile($config);
     // 实例化上传类
     $image = new Image();
     if (!$upload->upload()) {
         // 上传错误提示错误信息
         $msg = $upload->getErrorMsg();
         print_r("{\"status\": 0, \"msg\":\"" . $msg . "\"}");
     } else {
         // 上传成功 获取上传文件信息
         $info = $upload->getUploadFileInfo();
         // 			$imgPath = substr($info[0]['savepath'].$info[0]['savename'],1);
         $imgPath = $info[0]['savepath'] . $info[0]['savename'];
         $imgInfo = $image->getImageInfo($imgPath);
         $thumb = $info[0]['savepath'] . 'thumb_' . $info[0]['savename'];
         if ($imageMax[0] < $imgInfo['width'] || $imageMax[1] < $imgInfo['height']) {
             $image->thumb($imgPath, $imgPath, '', $imageMax[0], $imageMax[1]);
         }
         $image->thumb($imgPath, $info[0]['savepath'] . 'bthumb_' . $info[0]['savename'], '', $bthumbMax[0], $bthumbMax[1]);
         $image->thumb($imgPath, $info[0]['savepath'] . 'sthumb_' . $info[0]['savename'], '', $sthumbMax[0], $sthumbMax[1]);
         if (2 == $setInfo[6]['value']) {
             import(APP_NAME . ".Action.WaterMask");
             $water = new WaterMask($imgPath);
             $water->waterType = 0;
             //水印类型:0为文字水印、1为图片水印
             $water->pos = $setInfo[7]['value'];
             //水印位置
             $water->transparent = $setInfo[10]['value'] * 10;
             //水印透明度
             $water->waterStr = $setInfo[11]['value'];
             //水印文字
             $water->fontFile = "./Public/font/" . $setInfo[12]['value'] . ".ttf";
             //字体名称
             $water->fontSize = $setInfo[13]['value'];
             //字体大小
             $water->fontColor = array(255, 0, 255);
             //水印文字颜色(RGB值)
             $water->output();
             //输出水印图片
         } elseif (3 == $setInfo[6]['value']) {
             import(APP_NAME . ".Action.WaterMask");
             $water = new WaterMask($imgPath);
             $water->waterType = 1;
             //水印类型:0为文字水印、1为图片水印
             $water->pos = $setInfo[7]['value'];
             //水印位置
             $water->transparent = $setInfo[10]['value'] * 10;
             //水印透明度
             $water->waterStr = $setInfo[11]['value'];
             //水印文字
             $water->fontFile = "./Public/font/" . $setInfo[12]['value'] . ".ttf";
             //字体名称
             $water->fontSize = $setInfo[13]['value'];
             //字体大小
             $water->fontColor = array(255, 0, 255);
             //水印文字颜色(RGB值)
             $water->waterImg = "./Public/waterImg/" . $setInfo[9]['value'];
             //水印图片
             $water->output();
             //输出水印图片
         } else {
         }
         //写入登录日志
         $l = M('managerlog');
         $data['user_id'] = $_SESSION['userID'];
         $data['user_name'] = $_SESSION['userName'];
         $data['action_type'] = "uploadImg";
         $data['remark'] = "上传图片";
         $data['user_ip'] = $_SERVER["REMOTE_ADDR"];
         $data['add_time'] = date('y-m-d h:i:s', time());
         $data['time'] = time();
         $flag = $l->add($data);
         if ($flag) {
             print_r("{\"status\": 1,\"thumb\":\"" . substr($thumb, 1) . "\", \"path\": \"" . substr($imgPath, 1) . "\"}");
         } else {
             $this->error('用户日志操作失败,请重试');
         }
     }
 }
 /**
 +----------------------------------------------------------
 * 上传一个文件
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param mixed $name 数据
 * @param string $value  数据表名
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 private function save($file)
 {
     $filename = $file['savepath'] . $file['savename'];
     if (!$this->uploadReplace && is_file($filename)) {
         // 不覆盖同名文件
         $this->error = '文件已经存在!' . $filename;
         return false;
     }
     if (!move_uploaded_file($file['tmp_name'], auto_charset($filename, 'utf-8', 'gbk'))) {
         $this->error = '文件上传保存错误!';
         return false;
     }
     if ($this->thumb) {
         // 生成图像缩略图
         import("@.ORG.Image");
         $image = Image::getImageInfo($filename);
         if (false !== $image) {
             //是图像文件生成缩略图
             $thumbWidth = explode(',', $this->thumbMaxWidth);
             $thumbHeight = explode(',', $this->thumbMaxHeight);
             $thumbPrefix = explode(',', $this->thumbPrefix);
             $thumbSuffix = explode(',', $this->thumbSuffix);
             $thumbFile = explode(',', $this->thumbFile);
             $thumbPath = $this->thumbPath ? $this->thumbPath : $file['savepath'];
             for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) {
                 $thumbname = $thumbPath . $thumbPrefix[$i] . substr($file['savename'], 0, strrpos($file['savename'], '.')) . $thumbSuffix[$i] . '.' . $file['extension'];
                 Image::thumb($filename, $thumbname, '', $thumbWidth[$i], $thumbHeight[$i], true);
             }
             if ($this->thumbRemoveOrigin) {
                 // 生成缩略图之后删除原图
                 unlink($filename);
             }
         }
     }
     if ($this->zipImags) {
         // TODO 对图片压缩包在线解压
     }
     return true;
 }
Example #10
0
    $path = $_GET['path'];
} else {
    die(IMG_GEN_IMG_NOT_EXISTS);
}
require_once CLASS_HISTORY;
$history = new History($path, $session);
if (CONFIG_SYS_DEMO_ENABLE) {
    $sessionImageInfo = $history->getLastestRestorable();
    $originalSessionImageInfo = $history->getOriginalImage();
    if (sizeof($originalSessionImageInfo)) {
        $path = backslashToSlash($session->getSessionDir() . $originalSessionImageInfo['info']['name']);
    }
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . "inc" . DIRECTORY_SEPARATOR . "class.image.php";
$image = new Image();
$imageInfo = $image->getImageInfo($path);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="author" content="Logan Cai" />
<meta name="website" content="http://www.phpletter.com" />
<script type="text/javascript" src="js/ajaximageeditor_c.js"></script>

<!--<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/form.js"></script>
<script type="text/javascript" src="js/select.js"></script>
<script type="text/javascript" src="js/jqModal.js"></script>
<script type="text/javascript" src="js/rotate.js"></script>
<script type="text/javascript" src="js/interface.js"></script>-->
Example #11
0
 function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $warterMark = '', $interlace = true, $suffix = '_thumb')
 {
     // 获取原图信息
     $info = Image::getImageInfo($image);
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $pathinfo = pathinfo($image);
         $type = $pathinfo['extension'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         // 计算缩放比例
         // 缩略图尺寸
         $width = (int) ($srcWidth * $scale);
         $height = (int) ($srcHeight * $scale);
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         //创建缩略图
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         // 复制图片
         if (function_exists("ImageCopyResampled")) {
             ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         ImageDestroy($srcImg);
         /*
         //水印开始
         //计算水印的位置,默认居中
         $textInfo = Image::getImageInfo($warterMark);
         $textW	=	$textInfo["width"];
         $textH	=	$textInfo["height"];
         unset($textInfo);
         $mark = imagecreatefrompng($warterMark);
         $imgW	=	$width;
         $imgH	=	$width*$textH/$textW;
         $y		=	($height-$textH)/2;
         if(function_exists("ImageCopyResampled")){
         	ImageCopyResampled($thumbImg,$mark,0,$y,0,0, $imgW,$imgH, $textW,$textH);
         }else{
         	ImageCopyResized($thumbImg,$mark,0,$y,0,0,$imgW,$imgH,  $textW,$textH);
         }
         ImageDestroy($mark);
         //水印结束
         */
         if ('gif' == $type || 'png' == $type) {
             imagealphablending($thumbImg, FALSE);
             //取消默认的混色模式
             imagesavealpha($thumbImg, TRUE);
             //设定保存完整的 alpha 通道信息
             $background_color = ImageColorAllocate($thumbImg, 0, 255, 0);
             //  指派一个绿色
             imagecolortransparent($thumbImg, $background_color);
             //  设置为透明色,若注释掉该行则输出绿色的图
         }
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
             // 对jpeg图形设置隔行扫描
         }
         // 生成图片
         // $imageFun = 'image'.($type=='jpg'?'jpeg':$type);
         $imageFun = 'imagepng';
         $filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
         $imageFun($thumbImg, $filename);
         ImageDestroy($thumbImg);
         return $filename;
     }
     return false;
 }
 /**
  * 用于图片附件上传加水印回调方法
  * @param type $_this
  * @param type $fileInfo
  * @param type $params 
  */
 public static function water($_this, $fileInfo, $params)
 {
     import("Image");
     //水印文件
     $water = SITE_PATH . CONFIG_WATERMARKIMG;
     //水印位置
     $waterPos = (int) CONFIG_WATERMARKPOS;
     //水印透明度
     $alpha = (int) CONFIG_WATERMARKPCT;
     //jpg图片质量
     $quality = (int) CONFIG_WATERMARKQUALITY;
     foreach ($fileInfo as $file) {
         //原图文件
         $source = $file['savepath'] . $file['savename'];
         //图像信息
         $sInfo = Image::getImageInfo($source);
         //如果图片小于系统设置,不进行水印添加
         if ($sInfo["width"] < (int) CONFIG_WATERMARKMINWIDTH || $sInfo['height'] < (int) CONFIG_WATERMARKMINHEIGHT) {
             continue;
         }
         Image::water($source, $water, $source, $alpha, $waterPos, $quality);
     }
 }
Example #13
0
// 开始上传
$upload = new UploadFile($upload_config);
// 返回结果
$result = array();
if (!$upload->upload()) {
    $result = $upload->getErrorMsg();
} else {
    $result = $upload->getUploadFileInfo();
}
/**
 * die('<script>alert(\''.json_encode($result).'\');</script>');
 */
// 拼装回调参数
$files = array();
foreach ($result as $f) {
    $img = Image::getImageInfo($f['savepath'] . $f['savename']);
    //图片信息
    //die('<script>alert(\''.json_encode($f).'\');</script>');
    // $resource_url=$file1['original']='http://'.$_SERVER['HTTP_HOST'].'/upload/'.substr($f['savepath'],2).$f['savename'];
    $resource_url = $file1['original'] = SITE_PATH . 'upload/' . substr($f['savepath'], 2) . $f['savename'];
    $r_size = $file1['size'] = $f['size'];
    $r_width = $file1['width'] = isset($img['width']) ? $img['width'] : 0;
    $r_height = $file1['height'] = isset($img['height']) ? $img['height'] : 0;
    $r_oname = $file1['oname'] = substr($f['name'], 0, strrpos($f['name'], '.'));
    switch ($f['extension']) {
        case 'zip':
        case 'rar':
            $resource_type = 3;
            break;
        case 'flv':
            $resource_type = 2;
Example #14
0
 /**
  +----------------------------------------------------------
 * 生成缩略图
  +----------------------------------------------------------
 * @static
 * @access public
  +----------------------------------------------------------
 * @param string $image  原图
 * @param string $type 图像格式
 * @param string $thumbname 缩略图文件名
 * @param string $maxWidth  宽度
 * @param string $maxHeight  高度
 * @param string $position 缩略图保存目录
 * @param boolean $interlace 启用隔行扫描
  +----------------------------------------------------------
 * @return void
  +----------------------------------------------------------
 */
 static function thumb($image, $thumbname, $maxWidth, $maxHeight, $type = '', $interlace = true)
 {
     // 获取原图信息
     $info = Image::getImageInfo($image);
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         // 计算缩放比例
         if ($scale >= 1) {
             // 超过原图大小不再缩略
             $width = $srcWidth;
             $height = $srcHeight;
         } else {
             // 缩略图尺寸
             $width = (int) ($srcWidth * $scale);
             $height = (int) ($srcHeight * $scale);
         }
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         if (!function_exists($createFun)) {
             return false;
         }
         $srcImg = $createFun($image);
         //创建缩略图
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         //png和gif的透明处理 by luofei614
         if ('png' == $type) {
             imagealphablending($thumbImg, false);
             //取消默认的混色模式(为解决阴影为绿色的问题)
             imagesavealpha($thumbImg, true);
             //设定保存完整的 alpha 通道信息(为解决阴影为绿色的问题)
         } elseif ('gif' == $type) {
             $trnprt_indx = imagecolortransparent($srcImg);
             if ($trnprt_indx >= 0) {
                 //its transparent
                 $trnprt_color = imagecolorsforindex($srcImg, $trnprt_indx);
                 $trnprt_indx = imagecolorallocate($thumbImg, $trnprt_color['red'], $trnprt_color['green'], $trnprt_color['blue']);
                 imagefill($thumbImg, 0, 0, $trnprt_indx);
                 imagecolortransparent($thumbImg, $trnprt_indx);
             }
         }
         // 复制图片
         if (function_exists("ImageCopyResampled")) {
             imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         // 对jpeg图形设置隔行扫描
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         // 生成图片
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $imageFun($thumbImg, $thumbname);
         imagedestroy($thumbImg);
         imagedestroy($srcImg);
         return $thumbname;
     }
     return false;
 }
 /**
  *导入Events
  *@date 2010-10-16
  *@time 上午10:00:44
  */
 function event()
 {
     //导入Events
     import("ORG.Util.Image");
     $filename = $_GET['fname'];
     $act = $_GET['act'];
     if (empty($filename) && $act != 'hebing') {
         echo '<a href=' . __URL__ . "/event/fname/Guangzhou1110/>Guangzhou1110</a><br>";
         echo '<a href=' . __URL__ . "/event/fname/Shanghai1110/>Shanghai1110</a><br>";
         echo '<a href=' . __URL__ . "/event/fname/shenzhen20101109/>shenzhen20101109</a><br>";
         echo '<a href=' . __URL__ . "/event/fname/Beijing1111/>Beijing1111</a><br>";
         echo '<a href=' . __URL__ . "/event/act/hebing/>合并数据</a><br>";
         exit;
     }
     if ($act == 'hebing') {
         $newarr = array();
         $arr1 = S('Guangzhou1110');
         $arr2 = S('Shanghai1110');
         $arr3 = S('shenzhen20101109');
         $arr4 = S('Beijing1111');
         $newarr = array_merge($arr1, $arr2, $arr3, $arr4);
         shuffle($newarr);
         S('hebing', $newarr, 6000);
         if (S('hebing')) {
             echo "<a href='" . __URL__ . "/event/'>返回</a><br>";
             echo '写入成功';
         } else {
             echo '写入bu成功';
         }
         exit;
     }
     error_reporting(E_ALL);
     import("@.Com.PHPExcel", '', '.php');
     //import("@.Com.PHPExcel.IOFactory",'','.php');
     import("@.Com.PHPExcel.Reader.Excel5", '', '.php');
     import("@.Com.PHPExcel.Reader.Excel2007", '', '.php');
     $path = "Public/events/";
     $file = $path . $filename . '.xls';
     if (!file_exists($file)) {
         exit("文件'{$file}'不存在.\n");
     }
     $PHPExcel = new PHPExcel();
     $PHPReader = new PHPExcel_Reader_Excel5();
     $objPHPExcel = $PHPReader->load($file);
     $sheet = $objPHPExcel->getSheet(0);
     // 读取第一個工作表(编号从 0 开始)
     $highestRow = $sheet->getHighestRow();
     // 取得总行数
     $highestColumn = $sheet->getHighestColumn();
     // 取得总列数
     //$arr = array(1=>'A',2=>'B',3=>'C',4=>'D',5=>'E',6=>'F',7=>'G',8=>'H',9=>'I',10=>'J',11=>'K',12=>'L',13=>'M', 14=>'N',15=>'O',16=>'P',17=>'Q',18=>'R',19=>'S',20=>'T',21=>'U',22=>'V',23=>'W',24=>'X',25=>'Y',26=>'Z');
     $arr = array();
     if ($_GET['act'] == 'test') {
         $t = nl2br($sheet->getCellByColumnAndRow(1, 3)->getValue());
         dump($t);
         exit;
     }
     $warr = 0;
     $msg = '';
     $errnum = 0;
     for ($i = 2; $i <= $highestRow; $i++) {
         $arr[$i]['title'] = $sheet->getCellByColumnAndRow(0, $i)->getValue();
         if (empty($arr[$i]['title'])) {
             unset($arr[$i]);
             continue;
         }
         $arr[$i]['cid'] = $sheet->getCellByColumnAndRow(1, $i)->getValue();
         if (!is_float($arr[$i]['cid']) || empty($arr[$i]['cid'])) {
             unset($arr[$i]);
             continue;
         }
         $msg .= 'CID ' . $arr[$i]['cid'] . '___' . $sheet->getCellByColumnAndRow(2, $i)->getValue() . '-->' . $sheet->getCellByColumnAndRow(3, $i)->getValue();
         $time = $this->mkt($sheet->getCellByColumnAndRow(2, $i)->getValue());
         $arr[$i]['showstart'] = $time;
         $arr[$i]['showstart2'] = date("Y-m-d H:i:s", $time);
         $time = $this->mkt($sheet->getCellByColumnAndRow(3, $i)->getValue());
         $arr[$i]['showend'] = $time;
         $arr[$i]['showend2'] = date("Y-m-d H:i:s", $time);
         $arr[$i]['channel'] = 10;
         $l = $sheet->getCellByColumnAndRow(4, $i)->getValue();
         $arr[$i]['dir'] = $path . $filename . '/' . $l . '/';
         $arr[$i]['writer'] = $sheet->getCellByColumnAndRow(4, $i)->getValue();
         $arr[$i]['albumnum'] = $sheet->getCellByColumnAndRow(5, $i)->getValue();
         $arr[$i]['typeid'] = $sheet->getCellByColumnAndRow(6, $i)->getValue();
         if (empty($arr[$i]['typeid'])) {
             unset($arr[$i]);
             continue;
         }
         $msg .= 'typeid ' . $arr[$i]['typeid'] . '___';
         $arr[$i]['maps'] = $this->br_or_b($sheet->getCellByColumnAndRow(8, $i)->getValue());
         $arr[$i]['event']['detail'] = $this->br_or_b($sheet->getCellByColumnAndRow(7, $i)->getValue());
         $kw = str_word_count($arr[$i]['title'], 1);
         $keywords = "";
         foreach ($kw as $vkw) {
             $keywords .= $vkw . ',';
         }
         $arr[$i]['keywords'] = trim($keywords, ',');
         $arr[$i]['my_content'] = strip_tags($arr[$i]['event']['detail']);
         $arr[$i]['description'] = $arr[$i]['my_content'];
         if ($arr[$i]['albumnum'] || $arr[$i]['albumnum'] == '0') {
             $flist = $this->file_list($arr[$i]['dir']);
             //dump($flist);
             $img = count($flist);
             $num = $arr[$i]['albumnum'] + 1;
             if ($num != $img) {
                 $msg .= $l . '图片数量不正确实际图:' . $img . '填写图片:' . $arr[$i]['albumnum'] . "<br>\n";
                 $errnum++;
             } else {
                 $msg .= $l . "信息图片匹配<br>\n";
                 foreach ($flist as $v) {
                     $type = Image::getImageInfo($v);
                     if ($type['type'] == 'bmp') {
                         $msg .= '<b>' . $v . '图片格式不能是bmp</b><br>';
                         $warr++;
                     } elseif ($act == 'ok' && !empty($filename)) {
                         //是否确认写入
                         $filelen = strpos($v, '.');
                         //获取文件名长度
                         $filename_name = substr($v, 0, $filelen);
                         //截取文件名
                         $filename_name = end(explode("/", $filename_name));
                         $ext = strtolower(end(explode(".", $v)));
                         if ($filename_name == '0') {
                             $width = array('120', '514');
                             $height = array('140', '600');
                             $pre = array('s_', 'm_');
                             $fname = 's_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             $dir = $l . '/' . date("Y_m_d") . '/';
                             $spath = 'Public/event/exl' . $filename . '/' . $dir;
                             //dump($spath);
                             if (in_array($dir . $fname, $img_arr)) {
                                 $arr[$i]['picurl'] = '/' . $spath . $fname;
                                 $arr[$i]['pic'][]['filename'] = '/' . $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             } else {
                                 $img_arr[$i] = $dir . $fname;
                                 $this->mvimg($v, $spath, md5_file(auto_charset($v, 'utf-8', 'gbk')), $width, $height, $pre);
                                 $arr[$i]['picurl'] = '/' . $spath . $fname;
                                 $arr[$i]['pic'][]['filename'] = '/' . $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             }
                         } else {
                             $width = array('514');
                             $height = array('600');
                             $pre = array('m_');
                             $fname = 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             $dir = $l . '/' . date("Y_m_d") . '/';
                             $spath = 'Public/event/exl' . $filename . '/' . $dir;
                             if (in_array($dir . $fname, $img_arr)) {
                                 $arr[$i]['pic'][]['filename'] = '/' . $spath . $fname;
                             } else {
                                 $img_arr[$i] = $dir . $fname;
                                 $this->mvimg($v, $spath, md5_file(auto_charset($v, 'utf-8', 'gbk')), $width, $height, $pre);
                                 $arr[$i]['pic'][]['filename'] = '/' . $spath . $fname;
                             }
                         }
                     }
                     //图片不是BMP格式
                 }
                 //dump($arr[$i]['picurl']);
             }
         } else {
             $msg .= '<b>' . $l . "信息无图片</b><br>\n";
             $warr++;
         }
     }
     echo $msg;
     echo "<a href='" . __URL__ . "/event/fname/{$filename}/act/ok'>写入缓存文件</a><br>";
     if ($act == 'ok') {
         S($filename, $arr);
         echo "已经写入缓存";
     }
     dump($arr);
     /*foreach ($arr as $v){
     			echo $v['writer'].'-------';
     			echo $v['showstart2'].'-------';
     			echo $v['showend2'].'-------';
     			echo '<br>';
     		}*/
 }
 /**
  *导入活动数据
  *@date 2010-7-6
  *@time 下午02:34:57
  */
 function events()
 {
     //导入活动数据
     import("@.Com.OLERead");
     import("@.Com.Spreadsheet_Excel_Reader");
     import("ORG.Util.Image");
     $filename = $_GET['fname'];
     $act = $_GET['act'];
     if (empty($filename) && $act != 'hebing') {
         echo '<a href=' . __URL__ . "/events/fname/bj_20100827/>bj_20100827</a><br>";
         echo '<a href=' . __URL__ . "/events/fname/gz_20100825/>gz_20100825</a><br>";
         echo '<a href=' . __URL__ . "/events/fname/sh_20100826/>sh_20100826</a><br>";
         echo '<a href=' . __URL__ . "/events/fname/sz_20100824/>sz_20100824</a><br>";
         echo '<a href=' . __URL__ . "/events/act/hebing/>合并数据</a><br>";
         exit;
     }
     if ($act == 'hebing') {
         $newarr = array();
         $arr1 = S('bj_20100827');
         $arr2 = S('gz_20100825');
         $arr3 = S('sh_20100826');
         $arr4 = S('sz_20100824');
         $newarr = array_merge($arr1, $arr2, $arr3, $arr4);
         shuffle($newarr);
         S('hebing', $newarr, 6000);
         if (S('hebing')) {
             echo "<a href='" . __URL__ . "/events/'>返回</a><br>";
             echo '写入成功';
         } else {
             echo '写入bu成功';
         }
         exit;
     }
     $path = "Public/events/";
     $file = $path . $filename . '.xls';
     $arr = array();
     $data = new Spreadsheet_Excel_Reader();
     $data->setOutputEncoding('utf-8');
     $data->read($file);
     //error_reporting(E_ALL ^ E_NOTICE);
     //echo $data->sheets[0]['numRows'];
     //echo $data->sheets[0]['numCols'];
     //echo $data->sheets[0]['cells'][3][8];
     if (($act == 'ok' || $act == 'fdb') && !empty($filename)) {
         import("ORG.Io.Dir");
         if (is_dir('Public/event/exl' . $filename)) {
             Dir::del('Public/event/exl' . $filename);
         }
     }
     $arr = array();
     $msg = '';
     $errnum = 0;
     $warr = 0;
     $img_arr = array();
     if (empty($data->sheets[0])) {
         //dump($data->formatRecords);
         $this->error("0");
     }
     for ($i = 2; $i <= 220; $i++) {
         if ($data->sheets[0]['cells'][$i][16] == '1' || empty($data->sheets[0]['cells'][$i][1])) {
             continue;
         }
         $l = $data->sheets[0]['cells'][$i][4];
         if (strpos($l, '_')) {
             $l = end(explode('_', $l));
         }
         //dump($data->sheets[0]['cells'][$i]);
         $arr[$i]['title'] = $data->sheets[0]['cells'][$i][1];
         $arr[$i]['cid'] = $this->city($data->sheets[0]['cells'][$i][2]);
         if ($arr[$i]['cid'] == '0') {
             continue;
         }
         $msg .= 'CID ' . $arr[$i]['cid'] . '___';
         $time = $this->get_time($data->sheets[0]['cells'][$i][3]);
         $arr[$i]['showstart'] = $time['st'];
         $arr[$i]['showend'] = $time['et'];
         $arr[$i]['channel'] = 10;
         $arr[$i]['dir'] = $path . $filename . '/' . $l . '/';
         $arr[$i]['writer'] = $data->sheets[0]['cells'][$i][4];
         if (!empty($data->sheets[0]['cells'][$i][5]) || $data->sheets[0]['cells'][$i][5] == '0') {
             $arr[$i]['albumnum'] = $data->sheets[0]['cells'][$i][5];
         }
         if (empty($data->sheets[0]['cells'][$i][6])) {
             continue;
         }
         $arr[$i]['typeid'] = $this->get_etype($data->sheets[0]['cells'][$i][6]);
         $msg .= 'typeid ' . $arr[$i]['typeid'] . '___';
         $arr[$i]['maps'] = $this->br_or_b($data->sheets[0]['cells'][$i][8]);
         $arr[$i]['event']['detail'] = $this->br_or_b($data->sheets[0]['cells'][$i][7]);
         $kw = str_word_count($arr[$i]['title'], 1);
         $keywords = "";
         foreach ($kw as $vkw) {
             $keywords .= $vkw . ',';
         }
         $arr[$i]['keywords'] = trim($keywords, ',');
         $arr[$i]['my_content'] = strip_tags($arr[$i]['event']['detail']);
         $arr[$i]['description'] = $arr[$i]['my_content'];
         if ($arr[$i]['albumnum'] || $arr[$i]['albumnum'] == '0') {
             $flist = $this->file_list($arr[$i]['dir']);
             $img = count($flist);
             $num = $arr[$i]['albumnum'] + 1;
             if ($num != $img) {
                 $msg .= $data->sheets[0]['cells'][$i][4] . '图片数量不正确实际图:' . $img . '填写图片:' . $arr[$i]['albumnum'] . "<br>\n";
                 $errnum++;
             } else {
                 $msg .= $data->sheets[0]['cells'][$i][4] . "信息图片匹配<br>\n";
                 foreach ($flist as $v) {
                     $type = Image::getImageInfo($v);
                     if ($type['type'] == 'bmp') {
                         $msg .= '<b>' . $v . '图片格式不能是bmp</b><br>';
                         $warr++;
                     } elseif (($act == 'ok' || $act == 'fdb') && !empty($filename)) {
                         //是否确认写入
                         $filelen = strpos($v, '.');
                         //获取文件名长度
                         $filename_name = substr($v, 0, $filelen);
                         //截取文件名
                         $filename_name = end(explode("/", $filename_name));
                         $ext = strtolower(end(explode(".", $v)));
                         if ($filename_name == '0') {
                             $width = array('120', '514');
                             $height = array('140', '600');
                             $pre = array('s_', 'm_');
                             $fname = 's_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             $dir = $l['0'] . '/' . date("Y_m_d") . '/';
                             $spath = 'Public/event/exl' . $filename . '/' . $dir;
                             if (in_array($dir . $fname, $img_arr)) {
                                 $arr[$i]['picurl'] = $spath . $fname;
                                 $arr[$i]['pic'][]['filename'] = $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             } else {
                                 $img_arr[$i] = $dir . $fname;
                                 $this->mvimg($v, $spath, md5_file(auto_charset($v, 'utf-8', 'gbk')), $width, $height, $pre);
                                 $arr[$i]['picurl'] = $spath . $fname;
                                 $arr[$i]['pic'][]['filename'] = $spath . 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             }
                         } else {
                             $width = array('514');
                             $height = array('600');
                             $pre = array('m_');
                             $fname = 'm_' . md5_file(auto_charset($v, 'utf-8', 'gbk')) . '.' . $ext;
                             $dir = $l['0'] . '/' . date("Y_m_d") . '/';
                             $spath = 'Public/event/exl' . $filename . '/' . $dir;
                             if (in_array($dir . $fname, $img_arr)) {
                                 $arr[$i]['pic'][]['filename'] = $spath . $fname;
                             } else {
                                 $img_arr[$i] = $dir . $fname;
                                 $this->mvimg($v, $spath, md5_file(auto_charset($v, 'utf-8', 'gbk')), $width, $height, $pre);
                                 $arr[$i]['pic'][]['filename'] = $spath . $fname;
                             }
                         }
                     }
                     //图片不是BMP格式
                 }
                 //dump($arr[$i]['picurl']);
             }
         } else {
             $msg .= '<b>' . $data->sheets[0]['cells'][$i][4] . "信息无图片</b><br>\n";
             $warr++;
         }
     }
     //end 循环读取数据
     if ($act == 'ok') {
         $return = '';
         $arc = D("Archives");
         $event = D("Event");
         $arr = S('hebing');
         foreach ($arr as $d) {
             if (!empty($d['title']) && !empty($d['typeid'])) {
                 $acr_vo = '';
                 $arc_vo = $arc->create($d);
                 $aid = $arc->add($arc_vo);
                 if ($aid) {
                     $event_vo = $event->create($d['event']);
                     $event_vo['aid'] = $aid;
                     $eid = $event->add($event_vo);
                     $this->add_photo($aid, $d['pic'], $d['writer'], 11);
                     $return .= $d['writer'] . "写入成功!<br>\n";
                 } else {
                     $return .= $d['writer'] . "主档写入失败!<br>\n";
                 }
             } else {
                 $return .= $d['writer'] . "标题或分类为空写入失败!<br>\n";
             }
         }
         echo $return;
     } elseif ($act == 'fdb') {
         S($filename, $arr, 6000);
         if (S($filename)) {
             echo "<a href='" . __URL__ . "/events/'>返回</a><br>";
             echo '写入成功';
         } else {
             echo '写入bu成功';
         }
     } else {
         echo '共有' . $errnum . '错误!<br>' . $warr . "警告!<br>\n";
         echo $msg;
         echo "<a href='" . __URL__ . "/events/act/fdb/fname/" . $filename . "'>写入缓存</a><br>";
         echo "<a href='" . __URL__ . "/events/act/ok/fname/" . $filename . "'>写入数据</a>";
     }
 }
Example #17
0
 public static function CreateThumb($site, $image, $filename, $folder = 'files')
 {
     // directory
     $dir = SITES_LOCATION . '/' . $site['FriendlyId'] . '/' . $folder . '/';
     // set thumb size
     $target_w = THUMB_MAX_WIDTH;
     $target_h = THUMB_MAX_HEIGHT;
     list($curr_w, $curr_h, $type, $attr) = Image::getImageInfo($image);
     $ext = 'jpg';
     switch ($type) {
         // create image
         case IMAGETYPE_JPEG:
             $ext = 'jpg';
             break;
         case IMAGETYPE_PNG:
             $ext = 'png';
             break;
         case IMAGETYPE_GIF:
             $ext = 'gif';
             break;
         case 'image/svg+xml':
             $ext = 'svg';
             break;
         default:
             return false;
     }
     $scale_h = $target_h / $curr_h;
     $scale_w = $target_w / $curr_w;
     $factor_x = $curr_w / $target_w;
     $factor_y = $curr_h / $target_h;
     if ($factor_x > $factor_y) {
         $factor = $factor_y;
     } else {
         $factor = $factor_x;
     }
     $up_w = ceil($target_w * $factor);
     $up_h = ceil($target_h * $factor);
     $x_start = ceil(($curr_w - $up_w) / 2);
     $y_start = ceil(($curr_h - $up_h) / 2);
     switch ($type) {
         // create image
         case IMAGETYPE_JPEG:
             $n_img = imagecreatefromjpeg($image);
             break;
         case IMAGETYPE_PNG:
             $n_img = imagecreatefrompng($image);
             break;
         case IMAGETYPE_GIF:
             $n_img = imagecreatefromgif($image);
             break;
         case 'image/svg+xml':
             break;
         default:
             return false;
     }
     $dst_img = ImageCreateTrueColor($target_w, $target_h);
     switch ($type) {
         // fix for transparency issues
         case IMAGETYPE_PNG:
             imagealphablending($dst_img, true);
             imagesavealpha($dst_img, true);
             $transparent_color = imagecolorallocatealpha($dst_img, 0, 0, 0, 127);
             imagefill($dst_img, 0, 0, $transparent_color);
             break;
         case IMAGETYPE_GIF:
             $transparency_index = imagecolortransparent($dst_img);
             if ($transparency_index >= 0) {
                 $transparent_color = imagecolorsforindex($dst_img, $transparency_index);
                 $transparency_index = imagecolorallocate($dst_img, $transparent_color['red'], $transparent_color['green'], $transparent_color['blue']);
                 imagefill($dst_img, 0, 0, $transparency_index);
                 imagecolortransparent($dst_img, $transparency_index);
             }
             break;
         default:
             break;
     }
     // (for testing) die('curr_w='.$curr_w.' curr_h='.$curr_h.' x_start='.$x_start.' y_start='.$y_start.' target_w='.$target_w.' target_h='.$target_h.' up_w='.$up_w.' up_h='.$up_h);
     if ($type != 'image/svg+xml') {
         imagecopyresampled($dst_img, $n_img, 0, 0, $x_start, $y_start, $target_w, $target_h, $up_w, $up_h);
     }
     //return $dst_img;
     $full = $dir . 'thumbs/' . $filename;
     if (!file_exists($dir)) {
         mkdir($dir, 0777, true);
     }
     switch ($ext) {
         case 'jpg':
             imagejpeg($dst_img, $full, 100);
             break;
         case 'png':
             // save file locally
             imagepng($dst_img, $full);
             break;
         case 'gif':
             // save file locally
             imagegif($dst_img, $full);
             break;
         case 'svg':
             // save file locally
             copy($image, $full);
             break;
         default:
             return false;
             return true;
     }
 }
Example #18
0
 /**
 +----------------------------------------------------------
 * 上传一个文件
 +----------------------------------------------------------
 * @access private
 +----------------------------------------------------------
 * @param mixed $name 数据
 * @param string $value  数据表名
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 private function save($file)
 {
     $filename = $file['savepath'] . $file['savename'];
     if (!$this->uploadReplace && file_exists($filename)) {
         // 不覆盖同名文件
         $this->error = '文件已经存在!' . $filename;
         return false;
     }
     if (!move_uploaded_file($file['tmp_name'], $filename)) {
         $this->error = '文件上传保存错误!';
         return false;
     }
     if ($this->thumb) {
         // 生成图像缩略图
         import("ORG.Util.Image");
         $image = Image::getImageInfo($filename);
         if (false !== $image) {
             //是图像文件生成缩略图
             $thumbWidth = explode(',', $this->thumbMaxWidth);
             $thumbHeight = explode(',', $this->thumbMaxHeight);
             $thumbSuffix = explode(',', $this->thumbSuffix);
             for ($i = 0, $len = count($thumbWidth); $i < $len; $i++) {
                 $thumbname = Image::thumb($filename, '', '', $thumbWidth[$i], $thumbHeight[$i], true, $thumbSuffix[$i]);
             }
         }
     }
     if ($this->zipImags) {
         // TODO 对图片压缩包在线解压
     }
     return true;
 }
Example #19
0
 /**
  * @method GET
  */
 function get()
 {
     // get token
     $token = Utilities::ValidateJWTToken(apache_request_headers());
     // check if token is not null
     if ($token != NULL) {
         // get a reference to the site, user
         $site = Site::GetBySiteId($token->SiteId);
         $arr = array();
         if (FILES_ON_S3 == true) {
             $arr = S3::ListFiles($site, false, 'downloads');
         } else {
             $directory = SITES_LOCATION . '/' . $site['FriendlyId'] . '/downloads/';
             //get all image files with a .html ext
             $files = glob($directory . "*.*");
             $arr = array();
             $image_exts = array('gif', 'png', 'jpg', 'svg');
             //print each file name
             foreach ($files as $file) {
                 $f_arr = explode("/", $file);
                 $count = count($f_arr);
                 $filename = $f_arr[$count - 1];
                 // get extension
                 $parts = explode(".", $filename);
                 $ext = end($parts);
                 // get extension
                 $ext = strtolower($ext);
                 // convert to lowercase
                 // is image
                 $isImage = in_array($ext, $image_exts);
                 // get size of file
                 $size = filesize($file);
                 if ($isImage == true) {
                     $width = 0;
                     $height = 0;
                     try {
                         list($width, $height, $type, $attr) = Image::getImageInfo($directory . $filename);
                     } catch (Exception $e) {
                     }
                     $file = array('filename' => $filename, 'fullUrl' => $site['Domain'] . '/downloads/' . $filename, 'thumbUrl' => $site['Domain'] . '/downloads/thumbs/' . $filename, 'extension' => $ext, 'isImage' => $isImage, 'width' => $width, 'height' => $height, 'size' => number_format($size / 1048576, 2));
                     array_push($arr, $file);
                 } else {
                     if ($is_thumb == false) {
                         $file = array('filename' => $filename, 'fullUrl' => $site['Domain'] . '/downloads/' . $filename, 'thumbUrl' => $site['Domain'] . '/downloads/thumbs/' . $filename, 'thumbUrl' => 'n/a', 'extension' => $ext, 'isImage' => $isImage, 'width' => NULL, 'height' => NULL, 'size' => number_format($size / 1048576, 2));
                         array_push($arr, $file);
                     }
                 }
             }
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($arr);
         return $response;
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }
Example #20
0
//��ͼĿ¼
$thumbDir = "./thumb/";
$tempFile = $tempDir . $fileHash;
$thumbFile = $thumbDir . $fileHash . "_" . $w . "_" . $h . "_" . $t;
//�ж��Ƿ��滻
if (!$r) {
    //�ж��Ƿ����
    if (file_exists($thumbFile)) {
        $img->showImg($thumbFile);
        exit;
    }
}
//���������
if (copy($url, $tempFile)) {
    //�ж�ͼƬ��С ���ͼƬ��͸߶�С��Ҫ���ŵı��� ֱ�����
    $info = $img->getImageInfo($tempFile);
    if ($info['width'] <= $w && $info['height'] <= $h) {
        copy($tempFile, $thumbFile);
        $img->showImg($thumbFile, '', $info['width'], $info['height']);
        exit;
    } else {
        //������ͼ
        if ($t == 'c') {
            $thumb = $img->cutThumb($tempFile, $thumbFile, $w, $h);
        } elseif ($t == 'f') {
            $thumb = $img->thumb($tempFile, '', $thumbFile, $w, $h);
        }
        //�����ͼ
        $img->showImg($thumb, '', $w, $h);
        exit;
    }
Example #21
0
 /**
 +----------------------------------------------------------
 * 生成缩略图
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $image  原图
 * @param string $type 图像格式
 * @param string $filename 缩略图文件名
 * @param string $maxWidth  宽度
 * @param string $maxHeight  高度
 * @param string $position 缩略图保存目录
 * @param boolean $interlace 启用隔行扫描
 +----------------------------------------------------------
 * @return void
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 static function thumb($image, $type = '', $filename = '', $maxWidth = 200, $maxHeight = 50, $interlace = true, $suffix = '_thumb')
 {
     // 获取原图信息
     $info = Image::getImageInfo($image);
     if ($info == false) {
         file_put_contents('1.txt', 'wrong');
     }
     if ($info !== false) {
         $srcWidth = $info['width'];
         $srcHeight = $info['height'];
         $pathinfo = pathinfo($image);
         $type = $pathinfo['extension'];
         $type = empty($type) ? $info['type'] : $type;
         $type = strtolower($type);
         $interlace = $interlace ? 1 : 0;
         unset($info);
         $scale = min($maxWidth / $srcWidth, $maxHeight / $srcHeight);
         // 计算缩放比例
         // 缩略图尺寸
         $width = (int) ($srcWidth * $scale);
         $height = (int) ($srcHeight * $scale);
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $srcImg = $createFun($image);
         //创建缩略图
         if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
             $thumbImg = imagecreatetruecolor($width, $height);
         } else {
             $thumbImg = imagecreate($width, $height);
         }
         // 复制图片
         if (function_exists("ImageCopyResampled")) {
             ImageCopyResampled($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         } else {
             ImageCopyResized($thumbImg, $srcImg, 0, 0, 0, 0, $width, $height, $srcWidth, $srcHeight);
         }
         if ('gif' == $type || 'png' == $type) {
             //imagealphablending($thumbImg, false);//取消默认的混色模式
             //imagesavealpha($thumbImg,true);//设定保存完整的 alpha 通道信息
             $background_color = imagecolorallocate($thumbImg, 0, 255, 0);
             //  指派一个绿色
             imagecolortransparent($thumbImg, $background_color);
             //  设置为透明色,若注释掉该行则输出绿色的图
         }
         // 对jpeg图形设置隔行扫描
         if ('jpg' == $type || 'jpeg' == $type) {
             imageinterlace($thumbImg, $interlace);
         }
         // 生成图片
         $imageFun = 'image' . ($type == 'jpg' ? 'jpeg' : $type);
         $filename = empty($filename) ? substr($image, 0, strrpos($image, '.')) . $suffix . '.' . $type : $filename;
         $imageFun($thumbImg, $filename);
         ImageDestroy($thumbImg);
         ImageDestroy($srcImg);
         return $filename;
     }
     return false;
 }
 public function water($source, $water, $alpha = 80, $position = "4")
 {
     //检查文件是否存在
     if (!file_exists($source) || !file_exists($water)) {
         return false;
     }
     //图片信息
     $sInfo = Image::getImageInfo($source);
     $wInfo = Image::getImageInfo($water);
     //如果图片小于水印图片,不生成图片
     if ($sInfo["0"] < $wInfo["0"] || $sInfo['1'] < $wInfo['1']) {
         return false;
     }
     //建立图像
     $sCreateFun = "imagecreatefrom" . $sInfo['type'];
     if (!function_exists($sCreateFun)) {
         $sCreateFun = 'imagecreatefromjpeg';
     }
     $sImage = $sCreateFun($source);
     $wCreateFun = "imagecreatefrom" . $wInfo['type'];
     if (!function_exists($wCreateFun)) {
         $wCreateFun = 'imagecreatefromjpeg';
     }
     $wImage = $wCreateFun($water);
     //设定图像的混色模式
     imagealphablending($wImage, true);
     switch (intval($position)) {
         case 0:
             break;
             //左上
         //左上
         case 1:
             $posY = 0;
             $posX = 0;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //右上
         //右上
         case 2:
             $posY = 0;
             $posX = $sInfo[0] - $wInfo[0];
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //左下
         //左下
         case 3:
             $posY = $sInfo[1] - $wInfo[1];
             $posX = 0;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //右下
         //右下
         case 4:
             $posY = $sInfo[1] - $wInfo[1];
             $posX = $sInfo[0] - $wInfo[0];
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
             //居中
         //居中
         case 5:
             $posY = $sInfo[1] / 2 - $wInfo[1] / 2;
             $posX = $sInfo[0] / 2 - $wInfo[0] / 2;
             //生成混合图像
             imagecopymerge($sImage, $wImage, $posX, $posY, 0, 0, $wInfo[0], $wInfo[1], $alpha);
             break;
     }
     //如果没有给出保存文件名,默认为原图像名
     @unlink($source);
     //保存图像
     imagejpeg($sImage, $source, IMAGE_CREATE_QUALITY);
     imagedestroy($sImage);
     imagedestroy($wImage);
 }
Example #23
0
 /**
  * 把图像转换成字符显示
  * @static
  * @access public
  * @param string $image  要显示的图像
  * @param string $type  图像类型,默认自动获取
  * @return string
  */
 static function showASCIIImg($image, $string = '', $type = '')
 {
     $info = Image::getImageInfo($image);
     if ($info !== false) {
         $type = empty($type) ? $info['type'] : $type;
         unset($info);
         // 载入原图
         $createFun = 'ImageCreateFrom' . ($type == 'jpg' ? 'jpeg' : $type);
         $im = $createFun($image);
         $dx = imagesx($im);
         $dy = imagesy($im);
         $i = 0;
         $out = '<span style="padding:0px;margin:0;line-height:100%;font-size:1px;">';
         set_time_limit(0);
         for ($y = 0; $y < $dy; $y++) {
             for ($x = 0; $x < $dx; $x++) {
                 $col = imagecolorat($im, $x, $y);
                 $rgb = imagecolorsforindex($im, $col);
                 $str = empty($string) ? '*' : $string[$i++];
                 $out .= sprintf('<span style="margin:0px;color:#%02x%02x%02x">' . $str . '</span>', $rgb['red'], $rgb['green'], $rgb['blue']);
             }
             $out .= "<br>\n";
         }
         $out .= '</span>';
         imagedestroy($im);
         return $out;
     }
     return false;
 }
Example #24
0
 /**
  * @method GET
  */
 function get()
 {
     // get an authuser
     $authUser = new AuthUser();
     if (isset($authUser->UserUniqId)) {
         // check if authorized
         $arr = array();
         $site = Site::GetBySiteId($authUser->SiteId);
         $directory = '../sites/' . $site['FriendlyId'] . '/files/';
         //get all image files with a .html ext
         $files = glob($directory . "*.*");
         $arr = array();
         $image_exts = array('gif', 'png', 'jpg', 'svg');
         //print each file name
         foreach ($files as $file) {
             $f_arr = explode("/", $file);
             $count = count($f_arr);
             $filename = $f_arr[$count - 1];
             // get extension
             $parts = explode(".", $filename);
             $ext = end($parts);
             // get extension
             $ext = strtolower($ext);
             // convert to lowercase
             // is image
             $is_image = in_array($ext, $image_exts);
             // is thumb
             $is_thumb = false;
             if (substr($filename, 0, 2) == 't-') {
                 $is_thumb = true;
             }
             if ($is_thumb == false && $is_image == true) {
                 $width = 0;
                 $height = 0;
                 try {
                     list($width, $height, $type, $attr) = Image::getImageInfo($directory . $filename);
                 } catch (Exception $e) {
                 }
                 $file = array('filename' => $filename, 'fullUrl' => 'sites/' . $site['FriendlyId'] . '/files/' . $filename, 'thumbUrl' => 'sites/' . $site['FriendlyId'] . '/files/t-' . $filename, 'extension' => $ext, 'isImage' => $is_image, 'width' => $width, 'height' => $height);
                 array_push($arr, $file);
             } else {
                 if ($is_thumb == false) {
                     $file = array('filename' => $filename, 'fullUrl' => 'sites/' . $site['FriendlyId'] . '/files/' . $filename, 'thumbUrl' => 'n/a', 'extension' => $ext, 'isImage' => $is_image, 'width' => -1, 'height' => -1);
                     array_push($arr, $file);
                 }
             }
         }
         // return a json response
         $response = new Tonic\Response(Tonic\Response::OK);
         $response->contentType = 'application/json';
         $response->body = json_encode($arr);
         return $response;
     } else {
         // return an unauthorized exception (401)
         return new Tonic\Response(Tonic\Response::UNAUTHORIZED);
     }
 }