/** * 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; }