Posted by MinusCreative on Wed 30 Apr 05:28
report abuse | download | new post
- /*
- * The canvas master dimension will cause
- * your image to be resized without the borders
- * of the resulting image breaking into the
- * dimensions you specify in the resize:
- *
- * i.e. if you specify resize(500, 20, Image::CANVAS)
- * your image the resulting image may end up 500x350
- * or if it's a tall image, it could be 500x2000.
- * The point is; it will never be smaller on any side
- * than the minimum dimension you specify. This is
- * useful if you want to crop an image, using the
- * maximum amount of image possible independent of
- * its input or output aspect ratio and dimensions.
- */
- if ($properties['master'] === Image::CANVAS)
- {
- $tmp_image_ar = $width / $height;
- $canvas_ar = $properties['width'] / $properties['height'];
- if ($canvas_ar >= 1)
- {
- if ($tmp_image_ar >= 1)
- { // wide
- // wide enough
- if (($width*$canvas_ar) >= $height)
- {
- $properties['master'] = Image::HEIGHT;
- $properties['height'] = $properties['height'];
- }
- // not wide enough for our ar; it would break into the box
- else
- {
- $properties['master'] = Image::WIDTH;
- $properties['width'] = $properties['width'];
- }
- }
- else
- { // tall
- // tall enough
- if ($width >= ($height * $canvas_ar))
- {
- $properties['master'] = Image::HEIGHT;
- $properties['height'] = $properties['height'];
- }
- // not tall enough for our ar; it would break into the box
- else
- {
- $properties['master'] = Image::WIDTH;
- $properties['width'] = $properties['width'];
- }
- }
- }
- else
- {
- if ($tmp_image_ar >= 1)
- { // wide
- // wide enough
- if (($height * $canvas_ar) >= $width)
- {
- $properties['master'] = Image::WIDTH;
- $properties['width'] = $properties['width'];
- }
- // not wide enough for our ar; it would break into the box
- else
- {
- $properties['master'] = Image::HEIGHT;
- $properties['height'] = $properties['height'];
- }
- }
- else
- { // tall
- // tall enough
- if ($height >= ($width * $canvas_ar))
- {
- $properties['master'] = Image::WIDTH;
- $properties['width'] = $properties['width'];
- }
- // not tall enough for our ar; it would break into the box
- else
- {
- $properties['master'] = Image::HEIGHT;
- $properties['height'] = $properties['height'];
- }
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.