joomla/joomla-framework — pull request #223 by piotr-cz (2013-09-24 07:57:45+00:00)
Title: Feature: Image scaling method: SCALE_FIT

New scaling method: Scale to fit given boundaries.
result is centered vertically to center and horizontally to middle.

Note: There is [similar PR](https://github.com/joomla/joomla-cms/pull/1565) in Joomla-CMS.

## Usage
```PHP
// Load up image
$img = new Image(JPATH_SITE . '/images/powered_by.png');

// Resize
$img->resize(96, 96, Image::SCALE_FIT);

// Save new image to file
$img->toFile(JPATH_SITE . '/images/joomla_powered_by_resized.jpg', IMAGETYPE_JPEG, array('quality' => 85));
```

## Example

**Original image (150x35)**
![powered_by](https://f.cloud.github.com/assets/612953/825245/74a3b170-f05f-11e2-87e8-db846b78d983.png)

**Scaled to 96x96**
![powered_by_transparent](https://f.cloud.github.com/assets/612953/825247/8b02b8a8-f05f-11e2-8bf6-d3ef99033446.png)

**Scaled to 96x96 and used backgorundfill filter** (see #1562)
![powered_by_white](https://f.cloud.github.com/assets/612953/825250/990e99b2-f05f-11e2-96d3-259630cfc1a1.png)