/** * Calculates the cropping rectangle and the scaled size for an input image size. * * @param int[] $in_size - two element array of input dimensions (width, height) * @param string $coi - four character encoded string containing the center of interest (unused if max_crop=0) * @param ImageRect &$crop_rect - ImageRect containing the cropping rectangle or null if cropping is not required * @param int[] &$scale_size - two element array containing width and height of the scaled image */ function compute($in_size, $coi, &$crop_rect, &$scale_size) { $destCrop = new ImageRect($in_size); if ($this->max_crop > 0) { $ratio_w = $destCrop->width() / $this->ideal_size[0]; $ratio_h = $destCrop->height() / $this->ideal_size[1]; if ($ratio_w > 1 || $ratio_h > 1) { if ($ratio_w > $ratio_h) { $h = $destCrop->height() / $ratio_w; if ($h < $this->min_size[1]) { $idealCropPx = $destCrop->width() - floor($destCrop->height() * $this->ideal_size[0] / $this->min_size[1]); $maxCropPx = round($this->max_crop * $destCrop->width()); $destCrop->crop_h(min($idealCropPx, $maxCropPx), $coi); } } else { $w = $destCrop->width() / $ratio_h; if ($w < $this->min_size[0]) { $idealCropPx = $destCrop->height() - floor($destCrop->width() * $this->ideal_size[1] / $this->min_size[0]); $maxCropPx = round($this->max_crop * $destCrop->height()); $destCrop->crop_v(min($idealCropPx, $maxCropPx), $coi); } } } } $scale_size = array($destCrop->width(), $destCrop->height()); $ratio_w = $destCrop->width() / $this->ideal_size[0]; $ratio_h = $destCrop->height() / $this->ideal_size[1]; if ($ratio_w > 1 || $ratio_h > 1) { if ($ratio_w > $ratio_h) { $scale_size[0] = $this->ideal_size[0]; $scale_size[1] = floor(1.0E-6 + $scale_size[1] / $ratio_w); } else { $scale_size[0] = floor(1.0E-6 + $scale_size[0] / $ratio_h); $scale_size[1] = $this->ideal_size[1]; } } else { $scale_size = null; } $crop_rect = null; if ($destCrop->width() != $in_size[0] || $destCrop->height() != $in_size[1]) { $crop_rect = $destCrop; } }
function modus_index_category_thumbnails($items) { global $page, $template, $conf; if ('categories' != $page['section'] || !($wh = @$conf['modus_theme']['album_thumb_size'])) { return $items; } $template->assign('album_thumb_size', $wh); $def_params = ImageStdParams::get_custom($wh, $wh, 1, $wh, $wh); foreach (ImageStdParams::get_defined_type_map() as $params) { if ($params->max_height() == $wh) { $alt_params = $params; } } foreach ($items as &$item) { $src_image = $item['representative']['src_image']; $src_size = $src_image->get_size(); $deriv = null; if (isset($alt_params) && $src_size[0] >= $src_size[1]) { $dsize = $alt_params->compute_final_size($src_size); if ($dsize[0] >= $wh && $dsize[1] >= $wh) { $deriv = new DerivativeImage($alt_params, $src_image); $rect = new ImageRect($dsize); $rect->crop_h($dsize[0] - $wh, $item['representative']['coi']); $rect->crop_v($dsize[1] - $wh, $item['representative']['coi']); $l = -$rect->l; $t = -$rect->t; } } if (!isset($deriv)) { $deriv = new DerivativeImage($def_params, $src_image); $dsize = $deriv->get_size(); $l = intval($wh - $dsize[0]) / 2; $t = intval($wh - $dsize[1]) / 2; } $item['modus_deriv'] = $deriv; if (!empty($item['icon_ts'])) { $item['icon_ts']['TITLE'] = time_since($item['max_date_last'], 'month'); } $styles = array(); if ($l < -1 || $l > 1) { $styles[] = 'left:' . 100 * $l / $wh . '%'; } if ($t < -1 || $t > 1) { $styles[] = 'top:' . $t . 'px'; } if (count($styles)) { $styles = ' style=' . implode(';', $styles); } else { $styles = ''; } $item['MODUS_STYLE'] = $styles; } return $items; }