Пример #1
0
 public function actionCropImg()
 {
     if (EnvUtil::submitCheck("userSubmit")) {
         $params = $_POST;
         if (!isset($params) && empty($params)) {
             return null;
         }
         $tempAvatar = $params["src"];
         $avatarPath = "data/avatar/";
         $avatarBig = UserUtil::getAvatar($params["uid"], "big");
         $avatarMiddle = UserUtil::getAvatar($params["uid"], "middle");
         $avatarSmall = UserUtil::getAvatar($params["uid"], "small");
         if (LOCAL) {
             FileUtil::makeDirs($avatarPath . dirname($avatarBig));
         }
         FileUtil::createFile("data/avatar/" . $avatarBig, "");
         FileUtil::createFile("data/avatar/" . $avatarMiddle, "");
         FileUtil::createFile("data/avatar/" . $avatarSmall, "");
         Ibos::import("ext.ThinkImage.ThinkImage", true);
         $imgObj = new ThinkImage(THINKIMAGE_GD);
         $imgObj->open($tempAvatar)->crop($params["w"], $params["h"], $params["x"], $params["y"])->save($tempAvatar);
         $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig);
         $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle);
         $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall);
         $this->success(Ibos::lang("Upload avatar succeed"), $this->createUrl("home/personal", array("op" => "avatar")));
         exit;
     }
 }
Пример #2
0
 /**
  * 头像裁剪
  * @return json json数据
  */
 public function crop()
 {
     $src = './Uploads/' . $_REQUEST['picName'];
     $des = './Uploads/crop_' . $_REQUEST['picName'];
     import('ORG.Util.Image.ThinkImage');
     $thinkImage = new ThinkImage();
     $thinkImage->open($src);
     $src_w = $thinkImage->width();
     $src_h = $thinkImage->height();
     $des_x = $_REQUEST['x1'] / $_REQUEST['scale'];
     $des_y = $_REQUEST['y1'] / $_REQUEST['scale'];
     $thinkImage->crop($_REQUEST['w'] / $_REQUEST['scale'], $_REQUEST['h'] / $_REQUEST['scale'], $des_x, $des_y)->save($des);
     $table = M("Head_img");
     $cnt = $table->count();
     if ($cnt > 0) {
         $data['id'] = 1;
         $data['name'] = 'crop_' . $_REQUEST['picName'];
         $data['add_time'] = time();
         $table->save($data);
     } else {
         $data['name'] = 'crop_' . $_REQUEST['picName'];
         $data['add_time'] = time();
         $table->add($data);
     }
     $jsonData['status'] = true;
     $jsonData['msg'] = '保存成功';
     $this->ajaxReturn($jsonData);
 }
Пример #3
0
 function onAfterFileUpload($currentFolder, $uploadedFile, $sFilePath)
 {
     /*
     global $config;
     $watermarkSettings = $config['Plugin_Watermark'];
            
     $this->createWatermark($sFilePath, $watermarkSettings['source'], $watermarkSettings['marginRight'],
         $watermarkSettings['marginBottom'], $watermarkSettings['quality'], $watermarkSettings['transparency']);
     return true;
     */
     //若不是图像则直接返回==================
     $size = getimagesize($sFilePath);
     if (!$size) {
         return false;
     }
     //===============================
     $path = substr($sFilePath, 0, stripos($sFilePath, '/Upload/'));
     $waterFile = $path . '/App/Runtime/Data/water.php';
     if (is_file($waterFile)) {
         $data = (include_once $waterFile);
     } else {
         return false;
         //配置文件不存在
     }
     if ($data['WATER_ENABLE'] == 1) {
         $libFile = $path . '/App/Core/Extend/Library/ORG/Util/Image/ThinkImage.class.php';
         if (is_file($libFile)) {
             include_once $libFile;
         } else {
             return false;
             //无法加在图像库
         }
         $img = new ThinkImage(THINKIMAGE_GD, $sFilePath);
         $position = $data['WATER_POSITION'];
         if ($data['WATER_TYPE'] == 2) {
             //文字水印
             $text = $data['WATER_TEXT'];
             $font = $path . '/Public/font/' . $data['WATER_FONT'];
             $size = $data['WATER_TEXT_SIZE'];
             $color = $data['WATER_TEXT_COLOR'];
             $angle = $data['WATER_TEXT_ANGLE'];
             $offset = array($data['WATER_OFFSET_X'], $data['WATER_OFFSET_Y']);
             $img->text($text, $font, $size, $color, $position, $offset, $angle)->save($sFilePath);
         } else {
             if ($data['WATER_TYPE'] == 1) {
                 //图片水印
                 $pic = $_SERVER['DOCUMENT_ROOT'] . $data['WATER_PIC'];
                 if (!file_exists($pic)) {
                     return;
                 }
                 $img->water($pic, $position)->save($sFilePath);
             }
         }
     }
     return true;
 }
Пример #4
0
 public function uploadify()
 {
     $verifyToken = md5('instructions' . $_POST['timestamp']);
     if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
         $m_config = M('config');
         if (isset($_FILES['Filedata']['size']) && $_FILES['Filedata']['size'] != null) {
             import('@.ORG.UploadFile');
             $upload = new UploadFile();
             $upload->maxSize = 20000000;
             $upload->allowExts = array('jpg', 'jpeg', 'png', 'gif');
             $dirname = './Uploads/' . date('Ym', time()) . '/' . date('d', time()) . '/';
             if (!is_dir($dirname) && !mkdir($dirname, 0777, true)) {
                 $this->ajaxReturn(0, '上传目录不可写', 0);
                 die;
             }
             $upload->savePath = $dirname;
             if (!$upload->upload()) {
                 $this->ajaxReturn(0, $upload->getErrorMsg(), 0);
                 die;
             } else {
                 $info = $upload->getUploadFileInfo();
             }
         }
         if (is_array($info[0]) && !empty($info[0])) {
             $a['type'] = $info[0]['extension'];
             $a['path'] = $info[0]['savepath'] . $info[0]['savename'];
             $temp_size = getimagesize($info[0]['savepath'] . $info[0]['savename']);
             if ($info[0]['extension'] != 'gif' && $temp_size[0] > 500) {
                 $height = 500 * $temp_size[1] / $temp_size[0];
                 import('@.ORG.ThinkImage.ThinkImage');
                 $Think_img = new ThinkImage(THINKIMAGE_GD);
                 $Think_img->open($info[0]['savepath'] . $info[0]['savename'])->thumb(500, $height, 1)->save($info[0]['savepath'] . $info[0]['savename']);
                 $a['width'] = 500;
                 $a['height'] = $height;
             } else {
                 $a['width'] = $temp_size[0];
                 $a['height'] = $temp_size[1];
             }
             $this->ajaxReturn($a, '上传成功', 1);
         } else {
             $this->ajaxReturn(0, '上传失败', 0);
         }
     } else {
         $this->ajaxReturn(0, '非法操作', 0);
     }
 }
Пример #5
0
 private function setCommonBg($src)
 {
     $bgPath = "data/home/";
     $random = StringUtil::random(16);
     $bgBig = $random . "_big.jpg";
     $bgMiddle = $random . "_middle.jpg";
     $bgSmall = $random . "_small.jpg";
     FileUtil::createFile($bgPath . $bgBig, "");
     FileUtil::createFile($bgPath . $bgMiddle, "");
     FileUtil::createFile($bgPath . $bgSmall, "");
     Ibos::import("ext.ThinkImage.ThinkImage", true);
     $imgObj = new ThinkImage(THINKIMAGE_GD);
     $imgObj->open($src)->thumb(1000, 300, 1)->save($bgPath . $bgBig);
     $imgObj->open($src)->thumb(520, 156, 1)->save($bgPath . $bgMiddle);
     $imgObj->open($src)->thumb(400, 120, 1)->save($bgPath . $bgSmall);
     $data = array("desc" => "", "status" => 0, "system" => 0, "image" => $random);
     $addRes = BgTemplate::model()->add($data);
     return $addRes;
 }
Пример #6
0
 public function get_user_pic($uid, $ticket, $logo, $name)
 {
     $user_pic = "./imgpublic/user_" . $uid . ".jpg";
     if (!file_exists($user_pic)) {
         $pic = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
         $data = file_get_contents($pic);
         $filepath = "./imgpublic/";
         $filename = "ticket_" . $uid . ".jpg";
         $fp = @fopen($filepath . $filename, "w");
         @fwrite($fp, $data);
         fclose($fp);
         $ticket = $filepath . $filename;
         if (!empty($logo)) {
             $pic = $logo;
             $data = file_get_contents($pic);
             $filepath = "./imgpublic/";
             $filename = "logo_" . $uid . ".jpg";
             $fp = @fopen($filepath . $filename, "w");
             @fwrite($fp, $data);
             fclose($fp);
             $logo = $filepath . $filename;
         }
         import('ThinkImage', APP_PATH . 'Common/ThinkImage', '.class.php');
         $img = new ThinkImage(THINKIMAGE_GD, './card.jpg');
         $img->open($ticket)->thumb(250, 250)->save($ticket);
         if (!empty($logo)) {
             $img->open($logo)->thumb(70, 70)->save($logo);
         }
         //            if(!empty($logo)){
         //                $img->open('./card.jpg')->water($ticket, THINKIMAGE_WATER_SOUTHEAST)->water($logo, THINKIMAGE_WATER_NORTHWEST, 70)->text('我是'.$name,'./hei.ttf','16','#000000', THINKIMAGE_WATER_NORTH, 60)->text('我为疯狂玉米狗招商','./hei.ttf','16','#000000', THINKIMAGE_WATER_NORTH, 80)->save($user_pic);
         //            }
         //            else
         //            {
         //                $img->open('./card.jpg')->water($ticket, THINKIMAGE_WATER_SOUTHEAST)->text('我是'.$name,'./hei.ttf','16','#000000', THINKIMAGE_WATER_NORTH, 100)->text('我为疯狂玉米狗招商','./hei.ttf','16','#000000', THINKIMAGE_WATER_NORTH, 80)->save($user_pic);
         //            }
         if (!empty($logo)) {
             $img->open('./card.jpg')->water($ticket, THINKIMAGE_WATER_SOUTHEAST)->water($logo, [80, 50])->text('我是' . $name, './hei.ttf', '16', '#000000', [160, 80])->text('我为疯狂玉米狗招商', './hei.ttf', '16', '#000000', [160, 100])->save($user_pic);
         } else {
             $img->open('./card.jpg')->water($ticket, THINKIMAGE_WATER_SOUTHEAST)->text('我是' . $name, './hei.ttf', '16', '#000000', [160, 80])->text('我为疯狂玉米狗招商', './hei.ttf', '16', '#000000', [160, 100])->save($user_pic);
         }
     }
     return $user_pic;
 }
Пример #7
0
 public function get_user_pic($uid, $ticket, $logo, $name)
 {
     $user_pic = "./imgpublic/user_" . $uid . ".jpg";
     if (!file_exists($user_pic)) {
         $pic = 'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' . $ticket;
         $data = file_get_contents($pic);
         $filepath = "./imgpublic/";
         $filename = "ticket_" . $uid . ".jpg";
         $fp = @fopen($filepath . $filename, "w");
         @fwrite($fp, $data);
         fclose($fp);
         $ticket = $filepath . $filename;
         if (!empty($logo)) {
             $pic = $logo;
             $data = file_get_contents($pic);
             $filepath = "./imgpublic/";
             $filename = "logo_" . $uid . ".jpg";
             $fp = @fopen($filepath . $filename, "w");
             @fwrite($fp, $data);
             fclose($fp);
             $logo = $filepath . $filename;
         }
         import('ThinkImage', APP_PATH . 'Common/ThinkImage', '.class.php');
         $img = new ThinkImage(THINKIMAGE_GD, './card.jpg');
         $img->open($ticket)->thumb(270, 270)->save($ticket);
         if (!empty($logo)) {
             $img->open($logo)->thumb(60, 60)->save($logo);
         }
         define('THINKIMAGE_WATER_CENTER', 5);
         $name = substr($name, 0, 15);
         if (!empty($logo)) {
             $img->open('./card.jpg')->water($ticket, array(183, 438))->water($logo, array(290, 543))->text($name, './hei.ttf', '18', '#000000', array(150, 736))->save($user_pic);
         } else {
             $img->open('./card.jpg')->water($ticket, array(169, 823))->text($name, './hei.ttf', '18', '#000000', array(282, 721))->save($user_pic);
         }
     }
     return $user_pic;
 }
Пример #8
0
 public function actionPostimg()
 {
     $upload = FileUtil::getUpload($_FILES["pmimage"], "mobile");
     if (!$upload->save()) {
         echo "出错了";
     } else {
         $info = $upload->getAttach();
         $file = FileUtil::getAttachUrl() . "/" . $info["type"] . "/" . $info["attachment"];
         $fileUrl = FileUtil::fileName($file);
         $filePath = FileUtil::getAttachUrl() . "/" . $info["type"] . "/" . $info["attachdir"];
         $filename = "tumb_" . $info["attachname"];
         if (LOCAL) {
             FileUtil::makeDirs($filePath . dirname($filename));
         }
         FileUtil::createFile($filePath . $filename, "");
         Yii::import("ext.ThinkImage.ThinkImage", true);
         $imgObj = new ThinkImage(THINKIMAGE_GD);
         $imgObj->open($fileUrl)->thumb(180, 180, 1)->save($filePath . $filename);
         $content = "<a href='" . $fileUrl . "'><img src='" . $filePath . $filename . "' /></a>";
         $id = intval(isset($_POST["pmid"]) ? $_POST["pmid"] : 0);
         $touid = intval(isset($_POST["pmtouid"]) ? $_POST["touid"] : 0);
         if (!$id && $touid) {
             $data = array("content" => $content, "touid" => $touid, "type" => 1);
             $res = MessageContent::model()->postMessage($data, Yii::app()->user->uid);
             $message = array("listid" => $res, "IsSuccess" => true);
         } else {
             $res = MessageContent::model()->replyMessage($id, $content, Yii::app()->user->uid);
             if ($res) {
                 $message = array("IsSuccess" => true, "data" => Ibos::lang("Private message send success"));
             } else {
                 $message = array("IsSuccess" => false, "data" => Ibos::lang("Private message send fail"));
             }
         }
         $this->ajaxReturn($message, "JSONP");
     }
 }
Пример #9
0
 public function actionUpload()
 {
     if ($_FILES["avatar"]) {
         $upload = FileUtil::getUpload($_FILES["avatar"]);
         if (!$upload->save()) {
             echo "出错了";
         } else {
             $info = $upload->getAttach();
             $file = FileUtil::getAttachUrl() . "/" . $info["type"] . "/" . $info["attachment"];
             $fileUrl = FileUtil::fileName($file);
             $uid = Yii::app()->user->uid;
             $tempAvatar = $file;
             $avatarPath = "data/avatar/";
             $avatarBig = UserUtil::getAvatar($uid, "big");
             $avatarMiddle = UserUtil::getAvatar($uid, "middle");
             $avatarSmall = UserUtil::getAvatar($uid, "small");
             if (LOCAL) {
                 FileUtil::makeDirs($avatarPath . dirname($avatarBig));
             }
             FileUtil::createFile("data/avatar/" . $avatarBig, "");
             FileUtil::createFile("data/avatar/" . $avatarMiddle, "");
             FileUtil::createFile("data/avatar/" . $avatarSmall, "");
             Yii::import("ext.ThinkImage.ThinkImage", true);
             $imgObj = new ThinkImage(THINKIMAGE_GD);
             $imgTemp = $imgObj->open($tempAvatar);
             $params = array("w" => $imgTemp->width(), "h" => $imgTemp->height(), "x" => "0", "y" => "0");
             if ($params["h"] < $params["w"]) {
                 $params["x"] = ($params["w"] - $params["h"]) / 2;
                 $params["w"] = $params["h"];
             } else {
                 $params["y"] = ($params["h"] - $params["w"]) / 2;
                 $params["h"] = $params["w"];
             }
             $imgObj->open($tempAvatar)->crop($params["w"], $params["h"], $params["x"], $params["y"])->save($tempAvatar);
             $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig);
             $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle);
             $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall);
         }
     }
 }
Пример #10
0
 /**
  *
  * @图片处理
  * @$i		打开的图片
  * @width	保存的宽度
  * @height	保存的高度
  * @save		保存的图片名称
  * @作者		shop猫
  * @版权		宁波天发网络
  * @官网		http://www.tifaweb.com http://www.dswjcms.com
  */
 protected function imageProcessing($i, $width, $height, $save)
 {
     import('ORG.Util.Image.ThinkImage');
     $img = new ThinkImage();
     $img->open($i)->crop($img->width(), $img->height(), 0, 0, $width, $height)->save($save);
 }
Пример #11
0
 public function item_edit()
 {
     //资讯编辑
     if ($_POST) {
         $item = D("item");
         $item_id = $_POST['item_id'];
         $_POST['content'] = str_replace('src="/Uploads/Attached/', 'src="http://' . $_SERVER[SERVER_NAME] . '/Uploads/Attached/', $_POST['content']);
         //$_POST['color']=implode(',',array_filter(array_unique($_POST['color'])));
         //print_r($_POST[style]);exit;
         /*$_POST['style']=implode(',',$_POST[style]);
         		$_POST['titanium_id']=implode(',',$_POST[titanium_id]);*/
         $_POST['item_type'] = implode(',', $_POST['item_type']);
         $_POST['shop_type'] = implode(',', $_POST['shop_type']);
         //echo '<pre>';print_r($_POST);
         //die();
         if ($vo = $item->create()) {
             /*print_r($vo);*/
             $list = $item->save();
             /*echo $item->getLastSql();
               die();*/
             if ($list !== false) {
                 //添加关联商品
                 $gruop_item_id = array_filter(array_unique($_POST['gruop_item_id']));
                 $str_group_id = implode(',', $gruop_item_id);
                 $item_brother = M('item_brother');
                 $group_del['item_id'] = array('eq', $item_id);
                 $resg = $item_brother->where($group_del)->delete();
                 for ($ik = 0; $ik < count($gruop_item_id); $ik++) {
                     $data_gruop[] = array('item_id' => $item_id, 'brother_item_id' => $gruop_item_id[$ik]);
                 }
                 if (!empty($data_gruop)) {
                     $item_brother->addAll($data_gruop);
                 }
                 $item_images = M('item_images');
                 $item_images->where(array('item_id' => array('eq', $item_id)))->delete();
                 //添加商品图片
                 import('ORG.Util.Image.ThinkImage');
                 $images_thumb = $_POST['item_pic'];
                 $arraythumb = C('ITEM_THUMB');
                 $i = 0;
                 //print_r($images_thumb);exit;
                 foreach ($images_thumb as $key => $val) {
                     $filename = substr($val, strrpos($val, '/') + 1);
                     $filenamearr = explode('.', $filename);
                     if ($val == "") {
                         continue;
                     }
                     foreach ($arraythumb as $key1 => $val1) {
                         $filenamethumb = $_SERVER['DOCUMENT_ROOT'] . $val . '_' . $val1[0] . 'X' . $val1[1] . '.jpg';
                         $img = new ThinkImage(THINKIMAGE_GD, $_SERVER['DOCUMENT_ROOT'] . $val);
                         $img->thumb($val1[0], $val1[1], THINKIMAGE_THUMB_SCALING)->save($filenamethumb);
                     }
                     $data_image[] = array('item_id' => $item_id, 'img_path' => "{$val}", 'sort' => ++$i);
                 }
                 if (!empty($data_image)) {
                     $item_images->addAll($data_image);
                     $save_data['icon'] = $data_image[0]['img_path'];
                     $item->where("item_id={$item_id}")->save($save_data);
                 }
                 $this->success('数据保存成功!', "__APP__/Item/item_list/");
                 exit;
             } else {
                 $this->error("没有更新任何数据!", "__APP__/Item/item_list/");
             }
         } else {
             $this->error($item->getError());
         }
         exit;
     }
     /**新闻分类**/
     $newstype = M("newstype");
     $newstypeinfo = $newstype->where("is_del='0'")->order('sort ASC')->select();
     $this->assign('newstypearr', $newstypeinfo);
     //echo '<pre>';print_r($newstypeinfo);
     $item = M("item");
     $id = $_GET["_URL_"][2];
     $condition['item_id'] = $id;
     //使用查询条件
     $infoAll = $item->where($condition)->find();
     //$infoAll['style']=explode(',',$infoAll['style']);
     //$infoAll['titanium_id']=explode(',',$infoAll['titanium_id']);
     $this->assign('arr', $infoAll);
     // $color_arr=explode(',',$infoAll['color']);
     //print_r($color_arr);exit;
     //$this->assign('color_arr',$color_arr);
     $item_images = M('item_images');
     $list_image = $item_images->where("item_id=" . $infoAll[item_id])->order('img_id ASC')->select();
     $this->assign('list_image', $list_image);
     $item_brother = M('item_brother');
     $br_where['b.item_id'] = array('eq', $infoAll[item_id]);
     $brother_list = $item_brother->join('as b LEFT JOIN cms_item as i ON i.item_id=b.brother_item_id')->field('i.item_name,i.color,i.item_id')->where($br_where)->select();
     $this->assign('brother_list', $brother_list);
     $this->display();
 }
Пример #12
0
 public function saveavatar()
 {
     $where['status'] = 1;
     $where['member_id'] = intval(session('member_id'));
     $member = M('Member')->where($where)->find();
     if ($member) {
         //图片裁剪数据
         $params = $this->_post();
         //裁剪参数
         if (!isset($params) && empty($params)) {
             return;
         }
         //头像目录地址
         $path = './Uploads/avatar/';
         //要保存的图片
         $real_path = $path . md5($member['email'] . time()) . '.png';
         //临时图片地址
         $pic_path = $params['src'];
         import('@.ORG.ThinkImage.ThinkImage');
         $Think_img = new ThinkImage(THINKIMAGE_GD);
         //裁剪原图
         $Think_img->open($pic_path)->crop($params['w'], $params['h'], $params['x'], $params['y'])->save($real_path);
         //生成缩略图
         $Think_img->open($real_path)->thumb(100, 100, 1)->save($real_path);
         unlink($params['src']);
         if (M('Member')->where($where)->setField('avatar', $real_path)) {
             unlink($member['avatar']);
             $this->redirect('member/home', array(), 0, '页面跳转中...');
         } else {
             unlink($real_path);
             $this->success('上传头像失败');
         }
     }
 }
Пример #13
0
/**
 * 生成缩略图
 * @param string $imageFile
 */
function makeThumb($imageFile)
{
    if (!file_exists($imageFile)) {
        return false;
    }
    if (!yd_is_image($imageFile)) {
        return false;
    }
    $data = YdCache::readThumb();
    if ($data['THUMB_ENABLE'] == 1) {
        $w = $data['THUMB_WIDTH'];
        //缩略图宽度
        $h = $data['THUMB_HEIGHT'];
        //缩略图高度
        $type = $data['THUMB_TYPE'];
        //缩略图类型
        $filename = './Upload/thumb' . basename($imageFile);
        import('ORG.Util.Image.ThinkImage');
        $img = new ThinkImage(THINKIMAGE_GD, $imageFile);
        $img->thumb($w, $h, $type)->save($filename);
        if ($data['THUMB_WATER_ENABLE'] == 1) {
            //是否添加水印
            addWater($filename);
        }
        return $filename;
    } else {
        return $imageFile;
    }
}
Пример #14
0
 private function createImgIcon($tempFile, $outputName)
 {
     $outputFile = $this->_iconPath . $outputName;
     FileUtil::createFile($outputFile, "");
     Ibos::import("ext.ThinkImage.ThinkImage", true);
     $imgObj = new ThinkImage(THINKIMAGE_GD);
     $imgObj->open($tempFile)->save($outputFile);
     return true;
 }
Пример #15
0
 public function cropImg()
 {
     header('Content-Type:application/json; charset=utf-8');
     //图片裁剪数据
     $params = $this->_post();
     //裁剪参数
     if (!isset($params) && empty($params)) {
         return;
     }
     //头像目录地址
     $path = './avatar/';
     //要保存的图片
     $real_path = $path . $params['picName'];
     //临时图片地址
     $pic_path = $path . $params['picName'];
     import('ORG.Util.Image.ThinkImage');
     $Think_img = new ThinkImage(THINKIMAGE_GD);
     //裁剪原图
     $Think_img->open($pic_path)->crop($params['w'], $params['h'], $params['x'], $params['y'])->save($real_path);
     //生成缩略图
     $Think_img->open($real_path)->thumb(100, 100, 1)->save($path . $params['picName'] . '_100.jpg');
     $Think_img->open($real_path)->thumb(60, 60, 1)->save($path . $params['picName'] . '_60.jpg');
     $Think_img->open($real_path)->thumb(30, 30, 1)->save($path . $params['picName'] . '_30.jpg');
     #$this->success('上传头像成功');
     $data['pic1'] = __ROOT__ . '/avatar/' . $params['picName'] . '_100.jpg';
     $data['pic2'] = __ROOT__ . '/avatar/' . $params['picName'] . '_60.jpg';
     $data['pic3'] = __ROOT__ . '/avatar/' . $params['picName'] . '_30.jpg';
     echo json_encode($data);
 }
Пример #16
0
 public function actionIndex()
 {
     $operation = EnvUtil::getRequest("op");
     switch ($operation) {
         case "thumbpreview":
         case "waterpreview":
             $temp = Ibos::engine()->IO()->file()->getTempPath() . "/watermark_temp.jpg";
             if (LOCAL) {
                 if (is_file($temp)) {
                     @unlink($temp);
                 }
             }
             $quality = EnvUtil::getRequest("quality");
             $source = PATH_ROOT . "/static/image/watermark_preview.jpg";
             if ($operation == "waterpreview") {
                 $trans = EnvUtil::getRequest("trans");
                 $type = EnvUtil::getRequest("type");
                 $val = EnvUtil::getRequest("val");
                 $pos = EnvUtil::getRequest("pos");
                 if ($type == "image") {
                     $sInfo = ImageUtil::getImageInfo($source);
                     $wInfo = ImageUtil::getImageInfo($val);
                     if ($sInfo["width"] < $wInfo["width"] || $sInfo["height"] < $wInfo["height"]) {
                         Ibos::import("ext.ThinkImage.ThinkImage", true);
                         $imgObj = new ThinkImage(THINKIMAGE_GD);
                         $imgObj->open($val)->thumb(260, 77, 1)->save($val);
                     }
                     ImageUtil::water($source, $val, $temp, $pos, $trans, $quality);
                 } else {
                     $hexColor = EnvUtil::getRequest("textcolor");
                     $size = EnvUtil::getRequest("size");
                     $fontPath = EnvUtil::getRequest("fontpath");
                     $rgb = ConvertUtil::hexColorToRGB($hexColor);
                     ImageUtil::waterMarkString($val, $size, $source, $temp, $pos, $quality, $rgb, self::TTF_FONT_PATH . $fontPath);
                 }
                 $image = $temp;
             }
             if (!LOCAL) {
                 if (Ibos::engine()->IO()->file()->createFile($temp, file_get_contents($image))) {
                     $image = FileUtil::fileName($temp);
                 }
             }
             $data = array("image" => $image, "sourceSize" => ConvertUtil::sizeCount(FileUtil::fileSize($source)), "thumbSize" => ConvertUtil::sizeCount(FileUtil::fileSize($image)), "ratio" => sprintf("%2.1f", FileUtil::fileSize($image) / FileUtil::fileSize($source) * 100) . "%");
             $this->render("imagePreview", $data);
             exit;
             break;
         case "upload":
             return $this->imgUpload("watermark", true);
             break;
     }
     $formSubmit = EnvUtil::submitCheck("uploadSubmit");
     $uploadKeys = "attachdir,attachurl,thumbquality,attachsize,filetype";
     $waterMarkkeys = "watermarkminwidth,watermarkminheight,watermarktype,watermarkposition,watermarktrans,watermarkquality,watermarkimg,watermarkstatus,watermarktext,watermarkfontpath";
     if ($formSubmit) {
         $keys = $uploadKeys . "," . $waterMarkkeys;
         $keyField = explode(",", $keys);
         foreach ($_POST as $key => $value) {
             if (in_array($key, $keyField)) {
                 Setting::model()->updateSettingValueByKey($key, $value);
             } elseif ($key == "watermarkstatus") {
                 Setting::model()->updateSettingValueByKey("watermarkstatus", 0);
             }
         }
         CacheUtil::update(array("setting"));
         $this->success(Ibos::lang("Save succeed", "message"));
     } else {
         $upload = Setting::model()->fetchSettingValueByKeys($uploadKeys);
         $waterMark = Setting::model()->fetchSettingValueByKeys($waterMarkkeys);
         $fontPath = DashboardUtil::getFontPathlist(self::TTF_FONT_PATH);
         $data = array("upload" => $upload, "waterMark" => $waterMark, "fontPath" => $fontPath);
         $this->render("index", $data);
     }
 }
 public function cropImg()
 {
     //图片裁剪数据
     $params = $this->_post();
     //裁剪参数
     if (!isset($params) && empty($params)) {
         return;
     }
     $picName = $this->_post('picName');
     $picName = explode('/', $picName);
     //头像目录地址
     $path = './avatar/' . $picName[3] . '/';
     //要保存的图片
     $real_path = $path . $picName[4];
     //临时图片地址
     $pic_path = $real_path;
     $thumb = explode('.', $picName[4]);
     //返回的是除后缀名的文件名
     import('ORG.Util.ThinkImage.ThinkImage');
     $Think_img = new ThinkImage(THINKIMAGE_GD);
     //裁剪原图
     $Think_img->open($pic_path)->crop($params['w'], $params['h'], $params['x'], $params['y'])->save($real_path);
     //生成缩略图
     $Think_img->open($real_path)->thumb(100, 100, 1)->save($path . $thumb[0] . '_100.jpg');
     $Think_img->open($real_path)->thumb(60, 60, 1)->save($path . $thumb[0] . '_60.jpg');
     $Think_img->open($real_path)->thumb(30, 30, 1)->save($path . $thumb[0] . '_30.jpg');
     $this->success('上传头像成功');
     //@unlink($pic_path);//删除临时文件
 }
Пример #18
0
 private function cropImg()
 {
     $uid = Ibos::app()->user->uid;
     $tempAvatar = $_POST["src"];
     $avatarPath = "data/avatar/";
     $avatarBig = UserUtil::getAvatar($uid, "big");
     $avatarMiddle = UserUtil::getAvatar($uid, "middle");
     $avatarSmall = UserUtil::getAvatar($uid, "small");
     if (LOCAL) {
         FileUtil::makeDirs($avatarPath . dirname($avatarBig));
     }
     FileUtil::createFile("data/avatar/" . $avatarBig, "");
     FileUtil::createFile("data/avatar/" . $avatarMiddle, "");
     FileUtil::createFile("data/avatar/" . $avatarSmall, "");
     Ibos::import("ext.ThinkImage.ThinkImage", true);
     $imgObj = new ThinkImage(THINKIMAGE_GD);
     $imgObj->open($tempAvatar)->thumb(180, 180, 1)->save($avatarPath . $avatarBig);
     $imgObj->open($tempAvatar)->thumb(60, 60, 1)->save($avatarPath . $avatarMiddle);
     $imgObj->open($tempAvatar)->thumb(30, 30, 1)->save($avatarPath . $avatarSmall);
 }
Пример #19
0
<?php

require_once 'config.php';
if (!defined('IN_APP')) {
    exit('Access Deny');
}
$allowTypeList = array('image/gif', 'image/jpeg', 'image/png');
$uploadType = $_FILES['file']['type'];
if (!in_array($uploadType, $allowTypeList)) {
    exit('非法格式文件');
}
$pathInfo = pathinfo($_FILES['file']['name']);
$ts = md5(time());
$newfileName = $ts . $config['fileType'];
move_uploaded_file($_FILES['file']['tmp_name'], $config['path'] . "/" . $newfileName);
require_once dirname(__FILE__) . '/Driver/ThinkImage.class.php';
$img = new ThinkImage(THINKIMAGE_GD, $config['path'] . '/' . $newfileName);
$img->thumb(200, 200, THINKIMAGE_THUMB_CENTER)->save($config['path'] . '/' . $newfileName);
header('Location:gen.php?name=' . $ts);
Пример #20
0
include 'header.php';
if (!defined('IN_APP')) {
    exit('Access Deny');
}
require_once dirname(__FILE__) . '/Driver/ThinkImage.class.php';
$method = $_SERVER['REQUEST_METHOD'];
$isGet = strtolower($method) == "get" ? true : false;
$descArr = $_POST['desc'];
$name = $_GET['name'];
$filePath = $config['path'] . "/" . $name . $config['fileType'];
$modFilePath = $config['path'] . "/" . $name . "_mod" . $config['fileType'];
if (!file_exists($filePath)) {
    exit('文件不存在');
}
if (!file_exists($modFilePath)) {
    $img = new ThinkImage(THINKIMAGE_GD, $config['source'] . '/bg.jpg');
    $carry = 0;
    foreach ($descArr as $key => $value) {
        if ($key == 4) {
            continue;
        }
        if ($key == 0) {
            $img->water($config['path'] . "/" . $name . $config['fileType'], THINKIMAGE_WATER_CENTER);
        }
        $x = 20 + $key % 3 * 220;
        if ($key % 3 == 0) {
            $carry++;
        }
        $y = 180 + 220 * ($carry - 1);
        $fontSize = strlen($value) * 3 > 24 ? 12 : 14;
        $value = htmlspecialchars($value);
Пример #21
0
function api_crop_img()
{
    // 图片裁剪数据
    $params = $this->_post();
    $user_code = $params['code'];
    // 要保存图片名称(用户编码)
    $tmp_img = $params['src'];
    // 临时图片名称
    $tmp_path = VK_PUB_IMG . 'tmp/' . $tmp_img;
    // 临时图片完整路径
    $save_path = VK_PUB_IMG . 'user/' . $user_code . '.jpg';
    // 要保存图片完整路径
    // 引入扩展图片库
    import('ORG.Util.Image.ThinkImage');
    $ThinkImage = new ThinkImage(THINKIMAGE_GD);
    // 裁剪原图
    $ThinkImage->open($tmp_path)->crop($params['w'], $params['h'], $params['x'], $params['y'])->save($save_path);
    // 生成缩略图
    $ThinkImage->open($save_path)->thumb(120, 120, 1)->save(VK_PUB_IMG . 'user/' . $user_code . '_120.jpg');
    $ThinkImage->open($save_path)->thumb(60, 60, 1)->save(VK_PUB_IMG . 'user/' . $user_code . '_60.jpg');
    // 删除原文件
    @unlink($tmp_path);
    // 以上都没有问题返回成功状态和数据
    if (updateTable(TB_BAS_USER_INFO, array('user_photo' => 1), array('user_code' => $user_code), 'cover')) {
        $this->ajaxReturn($save_path, "success:api_crop_img", 1);
    } else {
        $this->ajaxReturn(0, "failed:api_crop_img", 0);
    }
}