Version: current

# Class GD

A wrapper class for GD-based images, with lots of manipulation functions.

  Object
  GD

Package: sapphire\filesystem
Located at sapphire/filesystem/GD.php

## Methods summary

`public` | # `__construct( mixed $filename = null )` #### Overrides `Object::__construct`
`public` | # `setGD( mixed $gd )`
`public` | # `getGD( )`
`public static` | # `set_default_quality( `GD::$quality` $quality )` Set the default image quality. Set the default image quality. #### Parameters $quality quality int A number from 0 to 100, 100 being the best quality.
`public` | # `setQuality( mixed $quality )` Set the image quality, used when saving JPEGs. Set the image quality, used when saving JPEGs.
`public` | # `croppedResize( mixed $width, mixed $height )` Resize an image to cover the given width/height completely, and crop off any overhanging edges. Resize an image to cover the given width/height completely, and crop off any overhanging edges.
`public` | # `fittedResize( mixed $width, mixed $height )` Resizes the image to fit within the given region. Behaves similarly to paddedResize but without the padding. Resizes the image to fit within the given region. Behaves similarly to paddedResize but without the padding.
`public` | # `hasGD( )`
`public` | # `resize( mixed $width, mixed $height )` Resize an image, skewing it as necessary. Resize an image, skewing it as necessary.
`public `GD`` | # `rotate( angle $angle )` Rotates image by given angle. Rotates image by given angle. #### Parameters $angle angle #### Returns ``GD`` GD
`public `GD`` | # `rotatePixelByPixel( angle $angle )` Rotates image by given angle. It's slow because makes it pixel by pixel rather than using built-in function. Used when imagerotate function is not available(i.e. Ubuntu) Rotates image by given angle. It's slow because makes it pixel by pixel rather than using built-in function. Used when imagerotate function is not available(i.e. Ubuntu) #### Parameters $angle angle #### Returns ``GD`` GD
`public `GD`` | # `crop( top $top, left $left, `GD::$width` $width, `GD::$height` $height )` Crop's part of image. Crop's part of image. #### Parameters $top top y position of left upper corner of crop rectangle $left left x position of left upper corner of crop rectangle $width width rectangle width $height height rectangle height #### Returns ``GD`` GD
`public integer` | # `getWidth( )` Method return width of image. Method return width of image. #### Returns `integer` width.
`public integer` | # `getHeight( )` Method return height of image. Method return height of image. #### Returns `integer` height
`public` | # `resizeByWidth( mixed $width )` Resize an image by width. Preserves aspect ratio. Resize an image by width. Preserves aspect ratio.
`public` | # `resizeByHeight( mixed $height )` Resize an image by height. Preserves aspect ratio Resize an image by height. Preserves aspect ratio
`public` | # `resizeRatio( mixed $maxWidth, mixed $maxHeight, mixed $useAsMinimum = false )` Resize the image by preserving aspect ratio. By default, it will keep the image inside the maxWidth and maxHeight Passing useAsMinimum will make the smaller dimension equal to the maximum corresponding dimension Resize the image by preserving aspect ratio. By default, it will keep the image inside the maxWidth and maxHeight Passing useAsMinimum will make the smaller dimension equal to the maximum corresponding dimension
`public static` | # `color_web2gd( mixed $image, mixed $webColor )`
`public` | # `paddedResize( `GD::$width` $width, `GD::$height` $height, backgroundColour $backgroundColor = "FFFFFF" )` Resize to fit fully within the given box, without resizing. Extra space left around the image will be padded with the background color. Resize to fit fully within the given box, without resizing. Extra space left around the image will be padded with the background color. #### Parameters $width width $height height $backgroundColor backgroundColour
`public` | # `greyscale( mixed $rv = 38, mixed $gv = 36, mixed $bv = 26 )` Make the image greyscale $rv = red value, defaults to 38 $gv = green value, defaults to 36 $bv = blue value, defaults to 26 Based (more or less entirely, with changes for readability) on code from http://www.teckis.com/scriptix/thumbnails/teck.html Make the image greyscale $rv = red value, defaults to 38 $gv = green value, defaults to 36 $bv = blue value, defaults to 26 Based (more or less entirely, with changes for readability) on code from http://www.teckis.com/scriptix/thumbnails/teck.html
`public` | # `makeDir( mixed $dirname )`
`public` | # `writeTo( mixed $filename )`

### Methods inherited from Object

`__call()`, `__toString()`, `__wakeup()`, `addMethodsFrom()`, `addStaticVars()`, `addWrapperMethod()`, `add_extension()`, `add_static_var()`, `allMethodNames()`, `cacheToFile()`, `cacheToFileWithArgs()`, `clearCache()`, `combined_static()`, `create()`, `createMethod()`, `create_from_string()`, `defineMethods()`, `exists()`, `extInstance()`, `extend()`, `getCustomClass()`, `getExtensionInstance()`, `getExtensionInstances()`, `get_extensions()`, `get_static()`, `hasExtension()`, `hasMethod()`, `has_extension()`, `invokeWithExtensions()`, `is_a()`, `loadCache()`, `parentClass()`, `parse_class_spec()`, `remove_extension()`, `sanitiseCachename()`, `saveCache()`, `set_stat()`, `set_static()`, `set_uninherited()`, `stat()`, `strong_create()`, `uninherited()`, `uninherited_static()`, `useCustomClass()`

### Magic methods summary

## Properties summary

`protected mixed` | $gd | #
`protected mixed` | $width | #
`protected mixed` | $height | #
`protected mixed` | $quality | #
`protected static integer` | $default_quality | #

### Properties inherited from Object

`$class`, `$extension_instances`, `$extensions`

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -