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; } }
/** * 头像裁剪 * @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); }
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; }
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; }
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); } } }
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; }
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); } }
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"); } }
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('上传头像失败'); } } }
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);//删除临时文件 }
/** * * @图片处理 * @$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); }
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); } }
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() { 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); }
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; }
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); }