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