public function makeThumb(PwImage $image, $thumbInfo, $store)
 {
     $quality = Wekit::C('attachment', 'thumb.quality');
     foreach ($thumbInfo as $key => $value) {
         $thumburl = $store->getAbsolutePath($value[0], $value[1]);
         PwUpload::createFolder(dirname($thumburl));
         $result = $image->makeThumb($thumburl, $value[2], $value[3], $quality, $value[4], $value[5]);
         if ($result === true && $image->filename != $thumburl) {
             $this->ifthumb |= 1 << $key;
             $this->_thumb[] = array($thumburl, $value[1] . $value[0]);
         }
     }
 }
Example #2
0
 public function initWaterWay()
 {
     if ($this->type == 1) {
         $water = new PwImage(Wind::getRealDir('REP:mark') . '/' . $this->file);
         if (!$water->isImage() || !$water->getSource()) {
             return false;
         }
     } else {
         if (!$this->text || strlen($this->fontcolor) != 7) {
             return false;
         }
         empty($this->fontfamily) && ($this->fontfamily = 'en_arial.ttf');
         empty($this->fontsize) && ($this->fontsize = 12);
         $this->fontfile = Wind::getRealDir('REP:font') . '/' . $this->fontfamily;
         $temp = imagettfbbox($this->fontsize, 0, $this->fontfile, $this->text);
         //取得使用 TrueType 字体的文本的范围
         $water = new stdClass();
         $water->width = $temp[2] - $temp[6];
         $water->height = $temp[3] - $temp[7];
         unset($temp);
     }
     return $water;
 }
Example #3
0
 protected function downloadThirdPlatformAvatar($uid, $avatar_url)
 {
     Wind::import('WSRV:base.WindidUtility');
     $image_content = WindidUtility::buildRequest($avatar_url, array(), true, 2, 'get');
     if ($image_content) {
         $temp_file = tempnam(PUBLIC_PATH . "data/tmp/", 'tmp_');
         $handle = fopen($temp_file, "w");
         if ($handle) {
             $res = fwrite($handle, $image_content);
             fclose($handle);
             Wind::import('WSRV:upload.action.WindidAvatarUpload');
             Wind::import('LIB:upload.PwUpload');
             $bhv = new WindidAvatarUpload($uid);
             $upload = new PwUpload($bhv);
             $value = array('name' => 'avatar.jpg', 'size' => 1024 * 1024 * 1, 'tmp_name' => $temp_file);
             $file = new PwUploadFile('_0', $value);
             $file->filename = $upload->filterFileName($bhv->getSaveName($file));
             $file->savedir = $bhv->getSaveDir($file);
             $file->store = Wind::getComponent($bhv->isLocal ? 'localStorage' : 'storage');
             $file->source = str_replace('attachment', 'windid/attachment', $file->store->getAbsolutePath($file->filename, $file->savedir));
             if (PwUpload::moveUploadedFile($value['tmp_name'], $file->source)) {
                 $image = new PwImage($file->source);
                 if ($bhv->allowThumb()) {
                     $thumbInfo = $bhv->getThumbInfo($file->filename, $file->savedir);
                     foreach ($thumbInfo as $key => $value) {
                         $thumburl = $file->store->getAbsolutePath($value[0], $value[1]);
                         $thumburl = str_replace('attachment', 'windid/attachment', $thumburl);
                         $result = $image->makeThumb($thumburl, $value[2], $value[3], $quality, $value[4], $value[5]);
                         if ($result === true && $image->filename != $thumburl) {
                             $ts = $image->getThumb();
                         }
                     }
                 }
             }
             @unlink($temp_file);
         }
     }
 }
 /**
  * 后台设置-附件缩略预览
  */
 public function viewAction()
 {
     list($thumb, $thumbsize_width, $thumbsize_height, $quality) = $this->getInput(array('thumb', 'thumbsize_width', 'thumbsize_height', 'quality'), 'post');
     Wind::import('LIB:image.PwImage');
     $image = new PwImage(Wind::getRealDir('REP:demo', false) . '/demo.jpg');
     $thumburl = Wind::getRealDir('PUBLIC:attachment', false) . '/demo_thumb.jpg';
     $image->makeThumb($thumburl, $thumbsize_width, $thumbsize_height, $quality, $thumb);
     $data = array('img' => Wekit::url()->attach . '/demo_thumb.jpg?' . time());
     $this->setOutput($data, 'data');
     $this->showMessage('ADMIN:success');
 }
Example #5
0
 /**
 * 修改头像
 * @access public
 * @return void
 * @example
 <pre>
 /index.php?m=native&c=user&a=doAvatar <br>
 post: securityKey <br>
 postdata: Filename <br>
 curl -X POST -F 'Filename=@icon1.jpg' -F 'csrf_token=aaa' -F '_json=1' -F 'securityKey=xx' -b 'csrf_token=aaa' '/index.php?m=native&c=user&a=doAvatar'
 </pre>
 */
 public function doAvatarAction()
 {
     $this->checkUserSessionValid();
     //
     Wind::import('WSRV:upload.action.WindidAvatarUpload');
     Wind::import('LIB:upload.PwUpload');
     $bhv = new WindidAvatarUpload($this->uid);
     $upload = new PwUpload($bhv);
     if (($result = $upload->check()) === true) {
         foreach ($_FILES as $key => $value) {
             if (!PwUpload::isUploadedFile($value['tmp_name']) || !$bhv->allowType($key)) {
                 continue;
             }
         }
         $file = new PwUploadFile($key, $value);
         if (($result = $upload->checkFile($file)) !== true) {
             $this->showError($result->getError());
         }
         $file->filename = $upload->filterFileName($bhv->getSaveName($file));
         $file->savedir = $bhv->getSaveDir($file);
         $file->store = Wind::getComponent($bhv->isLocal ? 'localStorage' : 'storage');
         $file->source = str_replace('attachment', 'windid/attachment', $file->store->getAbsolutePath($file->filename, $file->savedir));
         //
         if (!PwUpload::moveUploadedFile($value['tmp_name'], $file->source)) {
             $this->showError('upload.fail');
         }
         $image = new PwImage($file->source);
         if ($bhv->allowThumb()) {
             $thumbInfo = $bhv->getThumbInfo($file->filename, $file->savedir);
             foreach ($thumbInfo as $key => $value) {
                 $thumburl = $file->store->getAbsolutePath($value[0], $value[1]);
                 $thumburl = str_replace('attachment', 'windid/attachment', $thumburl);
                 //
                 $result = $image->makeThumb($thumburl, $value[2], $value[3], $quality, $value[4], $value[5]);
                 if ($result === true && $image->filename != $thumburl) {
                     $ts = $image->getThumb();
                 }
             }
         }
         $this->showMessage('success');
     }
     $this->showMessage('operate.fail');
 }