/** * {@inheritdoc} */ public function thumbnail($width, $height, $crop = false) { $sourceX = 0; $sourceY = 0; if ($crop) { $resizeDimensions = PixelMath::getMaxFit($width, $height, $this->getWidth(), $this->getHeight()); $finalWidth = $width; $finalHeight = $height; $sourceX = $resizeDimensions['width'] / 2 - $width / 2; $sourceY = $resizeDimensions['height'] / 2 - $height / 2; } else { $resizeDimensions = PixelMath::getBestFit($width, $height, $this->getWidth(), $this->getHeight()); $finalWidth = $resizeDimensions['width']; $finalHeight = $resizeDimensions['height']; } $this->resize($resizeDimensions['width'], $resizeDimensions['height'], false); $thumb = imagecreatetruecolor($finalWidth, $finalHeight); if (imagecopyresampled($thumb, $this->getResource(), 0, 0, $sourceX, $sourceY, $finalWidth, $finalHeight, $finalWidth, $finalHeight)) { $this->resource = $thumb; $this->updateResourceDimensions(); return true; } return false; }
public function testShouldReturnDimensionsUsingTargetDimensionsAsAMinimumWhenProportionsDoNotMatch() { $this->assertEquals(array('width' => 800, 'height' => 100), $this->pixelMath->getMaxFit(80, 100, 1600, 200)); }