function CalculateThumbnailDimensions() { $this->DebugMessage('CalculateThumbnailDimensions() starting with [W,H,sx,sy,sw,sh] initially set to [' . $this->source_width . ',' . $this->source_height . ',' . $this->sx . ',' . $this->sy . ',' . $this->sw . ',' . $this->sh . ']', __FILE__, __LINE__); //echo $this->source_width.'x'.$this->source_height.'<hr>'; $this->thumbnailCropX = $this->sx ? $this->sx >= 2 ? $this->sx : round($this->sx * $this->source_width) : 0; //echo $this->thumbnailCropX.'<br>'; $this->thumbnailCropY = $this->sy ? $this->sy >= 2 ? $this->sy : round($this->sy * $this->source_height) : 0; //echo $this->thumbnailCropY.'<br>'; $this->thumbnailCropW = $this->sw ? $this->sw >= 2 ? $this->sw : round($this->sw * $this->source_width) : $this->source_width; //echo $this->thumbnailCropW.'<br>'; $this->thumbnailCropH = $this->sh ? $this->sh >= 2 ? $this->sh : round($this->sh * $this->source_height) : $this->source_height; //echo $this->thumbnailCropH.'<hr>'; // limit source area to original image area $this->thumbnailCropW = max(1, min($this->thumbnailCropW, $this->source_width - $this->thumbnailCropX)); $this->thumbnailCropH = max(1, min($this->thumbnailCropH, $this->source_height - $this->thumbnailCropY)); $this->DebugMessage('CalculateThumbnailDimensions() starting with [x,y,w,h] initially set to [' . $this->thumbnailCropX . ',' . $this->thumbnailCropY . ',' . $this->thumbnailCropW . ',' . $this->thumbnailCropH . ']', __FILE__, __LINE__); if ($this->zc && $this->w && $this->h) { // Zoom Crop // retain proportional resizing we did above, but crop off larger dimension so smaller // dimension fully fits available space $scaling_X = $this->source_width / $this->w; $scaling_Y = $this->source_height / $this->h; if ($scaling_X > $scaling_Y) { // some of the width will need to be cropped $allowable_width = $this->source_width / $scaling_X * $scaling_Y; $this->thumbnailCropW = round($allowable_width); $this->thumbnailCropX = round(($this->source_width - $allowable_width) / 2); } elseif ($scaling_Y > $scaling_X) { // some of the height will need to be cropped $allowable_height = $this->source_height / $scaling_Y * $scaling_X; $this->thumbnailCropH = round($allowable_height); $this->thumbnailCropY = round(($this->source_height - $allowable_height) / 2); } else { // image fits perfectly, no cropping needed } $this->thumbnail_width = $this->w; $this->thumbnail_height = $this->h; $this->thumbnail_image_width = $this->thumbnail_width; $this->thumbnail_image_height = $this->thumbnail_height; } elseif ($this->iar && $this->w && $this->h) { // Ignore Aspect Ratio // stretch image to fit exactly 'w' x 'h' $this->thumbnail_width = $this->w; $this->thumbnail_height = $this->h; $this->thumbnail_image_width = $this->thumbnail_width; $this->thumbnail_image_height = $this->thumbnail_height; } else { $original_aspect_ratio = $this->thumbnailCropW / $this->thumbnailCropH; if ($this->aoe) { if ($this->w && $this->h) { $maxwidth = min($this->w, $this->h * $original_aspect_ratio); $maxheight = min($this->h, $this->w / $original_aspect_ratio); } elseif ($this->w) { $maxwidth = $this->w; $maxheight = $this->w / $original_aspect_ratio; } elseif ($this->h) { $maxwidth = $this->h * $original_aspect_ratio; $maxheight = $this->h; } else { $maxwidth = $this->thumbnailCropW; $maxheight = $this->thumbnailCropH; } } else { $maxwidth = phpthumb_functions::nonempty_min($this->w, $this->thumbnailCropW, $this->config_output_maxwidth); $maxheight = phpthumb_functions::nonempty_min($this->h, $this->thumbnailCropH, $this->config_output_maxheight); //echo $maxwidth.'x'.$maxheight.'<br>'; $maxwidth = min($maxwidth, $maxheight * $original_aspect_ratio); $maxheight = min($maxheight, $maxwidth / $original_aspect_ratio); //echo $maxwidth.'x'.$maxheight.'<hr>'; } $this->thumbnail_image_width = $maxwidth; $this->thumbnail_image_height = $maxheight; $this->thumbnail_width = $maxwidth; $this->thumbnail_height = $maxheight; $this->FixedAspectRatio(); } $this->thumbnail_width = max(1, floor($this->thumbnail_width)); $this->thumbnail_height = max(1, floor($this->thumbnail_height)); return true; }