Ejemplo n.º 1
0
 public function upload_images($request)
 {
     require_once MECATO_PLUGIN_DIR . 'inc/services/ImageService.php';
     $imageService = new ImageService();
     $id = $request['id'];
     try {
         $response = $imageService->addImage('file', $id, 'plato');
         if (gettype($response)) {
             return array('id' => $id);
         } else {
             return new WP_Error($response->get_error_code(), $response->get_error_message(), array('status' => 404));
         }
     } catch (Exception $ex) {
         return new WP_Error($ex->getCode(), $ex->getMessage(), array('status' => 501));
     }
 }
 public function execute()
 {
     $this->_beginBulkaction();
     $noderefs = $this->_getNodeRefs();
     foreach ($noderefs as $noderef) {
         if (!$noderef->getElement()->hasAspect('@images')) {
             $this->_failureBulkaction('Not an image', $noderef->getElement()->Slug, $noderef->Slug);
             continue;
         }
         try {
             $this->ImageService->rebuildMissingThumbnails($noderef);
             $this->_updateBulkaction($noderef->getElement()->Slug, $noderef->Slug);
         } catch (Exception $e) {
             $this->_failureBulkaction($e->getMessage(), $noderef->getElement()->Slug, $noderef->Slug);
         }
     }
     return $this->_endBulkaction();
 }
 protected function _buildCmsThumbnail($node)
 {
     $node = $this->RegulatedNodeService->getByNodeRef($node->getNodeRef(), new NodePartials('', '#original.fields'));
     //-----------
     // Build CMS thumbnail separately so that it's ready when this action completes.
     $file = $this->FileService->retrieveFileFromNode($node->getElement(), $node->getOutTag('#original')->TagLinkNodeRef);
     $cmsThumb = $this->ImageService->createAndStoreThumbnail($node->getElement(), $this->imagesThumbnailCmsSize, $file->getLocalPath(), $this->ImageService->filenameForNode($node));
     $tag = new Tag($cmsThumb->getElement()->getSlug(), $cmsThumb->Slug, '#thumbnails', $this->imagesThumbnailCmsSize, $this->imagesThumbnailCmsSize);
     $node->replaceOutTags('#thumbnails', array($tag));
     $this->RegulatedNodeService->edit($node);
 }
 protected function _importPhotosFromJson($file)
 {
     try {
         $contents = file_get_contents($file);
         $json = JSONUtils::decode($contents);
         foreach ($json as $v) {
             echo "importing {$v->title}...";
             $url = $v->src;
             $parts = parse_url($url);
             $slug = SlugUtils::createSlug(basename($parts['path']));
             preg_match('/(\\.\\w*)$/', $parts['path'], $ext);
             $nodeRef = $this->NodeRefService->oneFromAspect('@images');
             $nodeRef = $this->NodeRefService->generateNodeRef($nodeRef, $slug);
             $node = $nodeRef->generateNode();
             if (!$this->NodeService->refExists($node->getNodeRef())) {
                 // go fetch file from url
                 $data = $this->HttpRequest->fetchURL($url);
                 // create a unique output file name
                 $sourceFile = FileSystemUtils::secureTmpname($this->workDir, 'urlfetch', !empty($ext[1]) ? strtolower($ext[1]) : null);
                 file_put_contents($sourceFile, $data);
                 $node->Title = rtrim($v->title);
                 $node->Status = "published";
                 $node->ActiveDate = $this->DateFactory->newStorageDate();
                 $node = $this->ImageService->storeMedia($sourceFile, $node, basename($parts['path']));
                 $this->NodeService->add($node);
                 echo "done\n";
             } else {
                 echo "exists\n";
             }
             unset($nodeRef);
             unset($node);
         }
     } catch (Exception $e) {
         echo "Exception: " . $e->getMessage() . "\n";
     }
 }
Ejemplo n.º 5
0
 /**
  * @param int   $uid
  * @param int   $type
  * @param int   $rotation    'rotation' => 选装次数,
  * @param float $scale       'scale' => 缩放比例,
  * @param int   $x           'x' =>  剪切区域左上角x坐标,
  * @param int   $y           'y' => 剪切区域左上角y坐标,
  * @param int   $w           'w' => 剪裁区域宽度,
  * @param int   $h           'h' => 剪裁区域高度,
  * @param int   $originImgId 'origin_img_id' => 原始图片id
  *
  * @return array
  * @throws DevInvalidParamsException
  */
 public function cropImage($uid, $type = 0, $rotation, $scale, $x, $y, $w, $h, $originImgId)
 {
     $scale = filter_var($scale, FILTER_VALIDATE_FLOAT);
     $rotation = filter_var($rotation, FILTER_VALIDATE_INT, ['default' => 0]);
     $x = filter_var($x, FILTER_VALIDATE_FLOAT, ['default' => 0]);
     $y = filter_var($y, FILTER_VALIDATE_FLOAT, ['default' => 0]);
     $w = filter_var($w, FILTER_VALIDATE_INT);
     $h = filter_var($h, FILTER_VALIDATE_INT);
     $originImgId = filter_var($originImgId, FILTER_VALIDATE_INT);
     if (empty($scale) || empty($w) || empty($h) || empty($originImgId)) {
         throw new DevInvalidParamsException("invalid params");
     }
     $file = $this->getOriginPath($originImgId);
     if (empty($file)) {
         throw new DevInvalidParamsException("empty file uploaded");
     }
     $x = round($x / $scale);
     $y = round($y / $scale);
     $scaleW = round($w / $scale);
     $scaleH = round($h / $scale);
     $manager = new ImageManager();
     $image = $manager->make($file)->rotate($rotation * 90)->crop($scaleW, $scaleH, $x, $y)->resize($w, $h);
     $hash = $image->getImageSignature();
     $bscId = ImageService::getInstance()->createBsc($hash);
     //		$hash = $image->getImageSignature();
     //		$bscId = ImageService::getInstance()->createBsc($hash);
     $exif = $image->getExifJson();
     $hash = hash("sha256", $hash . $exif);
     $srcId = ImageService::getInstance()->createSrc($uid, $bscId, $type, $exif, $hash);
     $image->save($this->getOriginPath($bscId));
     $image->destroy();
     return [$bscId, $srcId];
 }
Ejemplo n.º 6
0
 public function getImageUrlToken($args = array(), $server = '', $is_system = 0)
 {
     global $_FANWE;
     if ($_FANWE['uid'] > 0 || $is_system) {
         if (empty($server)) {
             $server = ImageService::getServer();
         }
         if (empty($server)) {
             return false;
         }
         $token = array('code' => $server['code'], 'uid' => $_FANWE['uid'], 'max_upload' => (int) $_FANWE['setting']['max_upload'], 'saltkey' => $_FANWE['cookie']['saltkey'], 'system' => $is_system, 'ip' => $_FANWE['client_ip'], 'time' => TIME_UTC, 'args' => $args);
         $token = serialize($token);
         $authkey = md5($_FANWE['config']['security']['authkey'] . $server['code']);
         $result = array();
         $result['code'] = $server['code'];
         $result['url'] = $server['url'];
         $result['host'] = $server['host'];
         $result['host_port'] = $server['host_port'];
         $result['port'] = $server['port'];
         $result['path'] = $server['path'];
         $result['token'] = rawurlencode(authcode($token, 'ENCODE', $authkey));
         $result['image_server'] = ImageService::formatServer($server);
         return $result;
     } else {
         return false;
     }
 }
Ejemplo n.º 7
0
<?php

require_once "business/imageservice.php";
$service = new ImageService();
$imagelijst = $service->toonAlleImages();
?>

<style>
    table {
    }    

    tr {display: block;
        float: left;
    width: auto;
    box-sizing: border-box;} 

    
    td:nth-child(2n+1){
        width: 20px;
    }

    tr:nth-child(2n+1) {
        background: lightgrey;
    }
    
    tr{border: 1px black solid;}

    body{background: rgba(235,233,249,1);
background: -moz-linear-gradient(top, rgba(235,233,249,1) 0%, rgba(216,208,239,1) 50%, rgba(206,199,236,1) 51%, rgba(193,191,234,1) 100%);
background: -webkit-gradient(left top, left bottom, color-stop(0%, rgba(235,233,249,1)), color-stop(50%, rgba(216,208,239,1)), color-stop(51%, rgba(206,199,236,1)), color-stop(100%, rgba(193,191,234,1)));
background: -webkit-linear-gradient(top, rgba(235,233,249,1) 0%, rgba(216,208,239,1) 50%, rgba(206,199,236,1) 51%, rgba(193,191,234,1) 100%);