Esempio n. 1
0
 /**
  * 添加水印位置
  */
 private function testWaterPosition()
 {
     $file = dirname(__FILE__) . '/test.jpg';
     $imageJpg = Thumb::create($file, FALSE);
     $imageJpg->thumbNormalUpload();
     $imageJpg->setWaterImage(dirname(__FILE__) . '/watermark.png');
     $imageJpg->waterLeftTop(dirname(__FILE__) . '/testWater1.jpg');
     $imageJpg->waterLeftBottom(dirname(__FILE__) . '/testWater2.jpg');
     $imageJpg->waterRightTop(dirname(__FILE__) . '/testWater3.jpg');
     $imageJpg->waterRightBottom(dirname(__FILE__) . '/testWater4.jpg');
     $imageJpg->waterCenter(dirname(__FILE__) . '/testWater5.jpg');
 }
Esempio n. 2
0
 /**
  * 上传头像
  * 
  * 一次只能上传单个文件
  * 
  * @return array size.url
  */
 public function uploadAvatar()
 {
     if (Param::post('type', Param::TYPE_STRING) != 'avatar') {
         return $this->format(self::API_FAIL, Front::getInstance()->getHuiLang()->_('cdn.upload.type.error'));
     }
     $result = $this->preCheck();
     if (!$result['success']) {
         return $result;
     }
     $postAvatar = Param::post('avatar', Param::TYPE_ARRAY);
     $postImage = Param::file('avatar', Param::TYPE_ARRAY);
     if (empty($postAvatar['uid'])) {
         return $this->format(self::API_FAIL, Front::getInstance()->getHuiLang()->_('cdn.avatar.need.uid'));
     }
     $uid = $postAvatar['uid'];
     //需要检测原始上传的post参数
     if (!in_array($postAvatar['type'], $this->allowImageMime)) {
         return $this->format(self::API_FAIL, Front::getInstance()->getHuiLang()->_('cdn.upload.image.mime.error'));
     }
     try {
         $huiLang = Front::getInstance()->getHuiLang();
         //上传处理
         $result = array();
         $path = $this->getAvatarPath($postAvatar);
         foreach (array('180', '100', '50', '30') as $size) {
             $filepath = str_ireplace('{size}', $size, $path['file']);
             Thumb::create($postImage['tmp_name'])->thumbByCrop($size, $size, $filepath);
         }
         $result['url'] = $path['url'];
         return $this->format(self::API_SUCCESS, $huiLang->_('cdn.upload.suceess'), array(), $result);
     } catch (Exception $e) {
         return $this->format(self::API_FAIL, $e->getMessage());
     }
 }