/** * @return IMAGE_METRICS */ public function metrics() { $Result = new IMAGE_METRICS(); $Result->set_image($this); return $Result; }
/** * Return the width to use for the tag. * @param MUNGER $munger The transformation context. * @param string[] $attributes List of attributes for the tag * (retrieved from the token). * @return string * @access private */ protected function _calculate_width($munger, $attributes) { /* Prefer scale over width, discarding invalid scale values. * Retrieve width from the image only if scale is set or * width is not set and an outer area was generated (we want * to constrain the caption to the width of the image). */ $scale = read_array_index($attributes, 'scale'); $Result = read_array_index($attributes, 'width'); if ($scale) { if (substr($scale, -1, 1) == '%') { $scale = substr($scale, 0, -1); } if (!is_numeric($scale)) { $scale = ''; } } if ($scale || !$Result && $this->_has_outer_area()) { $attachment_name = read_array_index($attributes, 'attachment'); if ($attachment_name) { $src = '{att_thumb}/' . $attachment_name; } else { $src = read_array_index($attributes, 'src'); } $url = new URL($munger->resolve_url($src, Force_root_on)); if (!$url->has_domain() || $url->has_local_domain()) { include_once 'webcore/util/image.php'; $metrics = new IMAGE_METRICS(); $metrics->set_url($url->as_text()); if ($metrics->loaded()) { if ($scale) { $Result = ceil($metrics->original_width * $scale / 100) . 'px'; } else { $Result = $metrics->original_width . 'px'; } } elseif ($scale) { $Result = $scale . '%'; } } } return $Result; }