public function get_processed($raw = false)
 {
     $json = $raw;
     if (is_array($json)) {
         $item = $json;
         $orig_item = $item;
         // item gets overriden by a variant.
         if ($this->Tag->width() || $this->Tag->height()) {
             $variant_key = 'w' . $this->Tag->width() . 'h' . $this->Tag->height() . 'c' . ($this->Tag->crop() ? '1' : '0') . ($this->Tag->density() ? '@' . $this->Tag->density() . 'x' : '');
             if (isset($json['sizes'][$variant_key])) {
                 $item = $json['sizes'][$variant_key];
             }
         }
         if ($this->Tag->output() && $this->Tag->output() != 'path') {
             switch ($this->Tag->output()) {
                 case 'size':
                     return isset($item['size']) ? $item['size'] : 0;
                     break;
                 case 'h':
                 case 'height':
                     return isset($item['h']) ? $item['h'] : 0;
                     break;
                 case 'w':
                 case 'width':
                     return isset($item['w']) ? $item['w'] : 0;
                     break;
                 case 'filename':
                     return $item['path'];
                     break;
                 case 'mime':
                     return $item['mime'];
                     break;
                 case 'tag':
                     // include inline?
                     if ($this->Tag->include() == 'inline' && isset($item['mime'])) {
                         if (strpos($item['mime'], 'svg')) {
                             $this->processed_output_is_markup = true;
                             return file_get_contents($this->_get_image_file($orig_item, $item));
                             break;
                         }
                     }
                     $attrs = array('src' => $this->_get_image_src($orig_item, $item));
                     if (!PERCH_RWD) {
                         $attrs['width'] = isset($item['w']) ? $item['w'] : '';
                         $attrs['height'] = isset($item['h']) ? $item['h'] : '';
                     }
                     $tags = array('class', 'title', 'alt');
                     $dont_escape = array();
                     foreach ($tags as $tag) {
                         if ($this->Tag->{$tag}()) {
                             $val = $this->Tag->{$tag}();
                             if (substr($val, 0, 1) == '{' && substr($val, -1) == '}') {
                                 $attrs[$tag] = '<' . $this->Tag->tag_name() . ' id="' . str_replace(array('{', '}'), '', $val) . '" escape="true" />';
                                 $dont_escape[] = $tag;
                             } else {
                                 $attrs[$tag] = PerchUtil::html($val, true);
                             }
                         }
                     }
                     $this->processed_output_is_markup = true;
                     return PerchXMLTag::create('img', 'single', $attrs, $dont_escape);
                     break;
             }
         }
         return $this->_get_image_src($orig_item, $item);
     }
     if ($this->Tag->width() || $this->Tag->height()) {
         $PerchImage = new PerchImage();
         return $PerchImage->get_resized_filename($raw, $this->Tag->width(), $this->Tag->height());
     }
     return PERCH_RESPATH . '/' . str_replace(PERCH_RESPATH . '/', '', $raw);
 }
Exemple #2
0
 if (isset($_GET['height']) && is_numeric($_GET['height'])) {
     $height = (int) $_GET['height'];
 }
 if (isset($_GET['quality']) && is_numeric($_GET['quality'])) {
     $quality = (int) $_GET['quality'];
 }
 if (isset($_GET['density']) && is_numeric($_GET['density'])) {
     $density = (int) $_GET['density'];
 }
 if (isset($_GET['sharpen']) && is_numeric($_GET['sharpen'])) {
     $sharpen = (int) $_GET['sharpen'];
 }
 if (isset($_GET['crop']) && $_GET['crop'] == 'true') {
     $crop = true;
 }
 $PerchImage = new PerchImage();
 if ($quality) {
     $PerchImage->set_quality($quality);
 }
 if ($sharpen) {
     $PerchImage->set_sharpening($sharpen);
 }
 if ($density) {
     $PerchImage->set_density($density);
 }
 $result = $PerchImage->resize_image($target['path'], $width, $height, $crop);
 if (is_array($result)) {
     if (isset($result['web_path'])) {
         $urlpath = $Bucket->get_web_path() . '/' . $result['file_name'];
     }
 }
 /**
  * Get the file size, and other meta like dimensions for images
  * @return [type] [description]
  */
 public function get_meta()
 {
     $file_path = $this->file_path();
     $out = array();
     $out['resourceFileSize'] = 0;
     if (file_exists($file_path)) {
         $out['resourceFileSize'] = filesize($file_path);
     }
     if ($this->is_image() && $out['resourceFileSize'] > 0) {
         $Image = new PerchImage();
         $out['resourceCrop'] = 0;
         if ($this->resourceType() == 'svg') {
             $info = $Image->get_svg_size($file_path);
         } else {
             PerchUtil::debug('Get image size: ' . $file_path);
             $info = getimagesize($file_path);
         }
         if ($info) {
             $out['resourceWidth'] = $info[0];
             $out['resourceHeight'] = $info[1];
         }
         if ($info && isset($info['mime'])) {
             $out['resourceMimeType'] = $info['mime'];
         } else {
             $out['resourceMimeType'] = PerchUtil::get_mime_type($this->file_path());
         }
         // get target info from file name
         $targets = $Image->parse_file_name($this->resourceFile());
         if ($targets) {
             if (isset($targets['w'])) {
                 $out['resourceTargetWidth'] = $targets['w'];
             }
             if (isset($targets['h'])) {
                 $out['resourceTargetHeight'] = $targets['h'];
             }
             if (isset($targets['c'])) {
                 $out['resourceCrop'] = $targets['c'];
             }
             if (isset($targets['d'])) {
                 $out['resourceDensity'] = $targets['d'];
                 $out['resourceWidth'] = $out['resourceWidth'] / $targets['d'];
                 $out['resourceHeight'] = $out['resourceHeight'] / $targets['d'];
                 PerchUtil::debug('Yes');
             }
         }
         if (isset($out['resourceWidth']) && isset($out['resourceTargetWidth']) && isset($out['resourceHeight']) && isset($out['resourceTargetHeight'])) {
             if ($out['resourceWidth'] == $out['resourceTargetWidth'] && $out['resourceHeight'] == $out['resourceTargetHeight']) {
                 $out['resourceCrop'] = '1';
             }
         }
     } else {
         $out['resourceMimeType'] = PerchUtil::get_mime_type($this->file_path());
     }
     if (isset($out['resourceWidth'])) {
         $out['resourceWidth'] = (int) $out['resourceWidth'];
     }
     if (isset($out['resourceHeight'])) {
         $out['resourceHeight'] = (int) $out['resourceHeight'];
     }
     return $out;
 }