Version: current

# Class Image

Represents an image attached to a page.

  Object
  ViewableData implements IteratorAggregate
  DataObject implements DataObjectInterface, i18nEntityProvider
  File
  Image

### Direct known subclasses

`Image_Cached`, `MediawebPage_Image`

Package: sapphire\filesystem
Located at sapphire/core/model/Image.php

## Methods summary

`public` | # `defineMethods( )` Set up template methods to access the transformations generated by 'generate' methods. Set up template methods to access the transformations generated by 'generate' methods. #### Overrides `DataObject::defineMethods`
`public boolean` | # `exists( )` An image exists if it has a filename. An image exists if it has a filename. #### Returns `boolean` boolean #### Overrides `DataObject::exists`
`public string` | # `getTag( )` Return an XHTML img tag for this Image. Return an XHTML img tag for this Image. #### Returns `string` string
`public string` | # `forTemplate( )` Return an XHTML img tag for this Image. Return an XHTML img tag for this Image. #### Returns `string` string
`public` | # `loadUploadedImage( mixed $tmpFile )`
`public` | # `SetWidth( mixed $width )`
`public` | # `SetHeight( mixed $height )`
`public` | # `SetSize( mixed $width, mixed $height )`
`public` | # `SetRatioSize( mixed $width, mixed $height )`
`public` | # `generateSetRatioSize( `GD` $gd, mixed $width, mixed $height )`
`public `GD`` | # `generateSetWidth( `GD` $gd, mixed $width )` Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth. Resize this Image by width, keeping aspect ratio. Use in templates with $SetWidth. #### Returns ``GD`` GD
`public `GD`` | # `generateSetHeight( `GD` $gd, mixed $height )` Resize this Image by height, keeping aspect ratio. Use in templates with $SetHeight. Resize this Image by height, keeping aspect ratio. Use in templates with $SetHeight. #### Returns ``GD`` GD
`public `GD`` | # `generateSetSize( `GD` $gd, mixed $width, mixed $height )` Resize this Image by both width and height, using padded resize. Use in templates with $SetSize. Resize this Image by both width and height, using padded resize. Use in templates with $SetSize. #### Returns ``GD`` GD
`public` | # `CMSThumbnail( )` #### Overrides `File::CMSThumbnail`
`public `GD`` | # `generateCMSThumbnail( `GD` $gd )` Resize this image for the CMS. Use in templates with $CMSThumbnail. Resize this image for the CMS. Use in templates with $CMSThumbnail. #### Returns ``GD`` GD
`public `GD`` | # `generateAssetLibraryPreview( `GD` $gd )` Resize this image for preview in the Asset section. Use in templates with $AssetLibraryPreview. Resize this image for preview in the Asset section. Use in templates with $AssetLibraryPreview. #### Returns ``GD`` GD
`public `GD`` | # `generateAssetLibraryThumbnail( `GD` $gd )` Resize this image for thumbnail in the Asset section. Use in templates with $AssetLibraryThumbnail. Resize this image for thumbnail in the Asset section. Use in templates with $AssetLibraryThumbnail. #### Returns ``GD`` GD
`public `GD`` | # `generateStripThumbnail( `GD` $gd )` Resize this image for use as a thumbnail in a strip. Use in templates with $StripThumbnail. Resize this image for use as a thumbnail in a strip. Use in templates with $StripThumbnail. #### Returns ``GD`` GD
`public` | # `generatePaddedImage( `GD` $gd, mixed $width, mixed $height )`
`public `Image_Cached`` | # `getFormattedImage( string $format, string $arg1 = null, string $arg2 = null )` Return an image object representing the image in the given format. This image will be generated using generateFormattedImage(). The generated image is cached, to flush the cache append ?flush=1 to your URL. Return an image object representing the image in the given format. This image will be generated using generateFormattedImage(). The generated image is cached, to flush the cache append ?flush=1 to your URL. #### Parameters $format string $format The name of the format. $arg1 string $arg1 An argument to pass to the generate function. $arg2 string $arg2 A second argument to pass to the generate function. #### Returns ``Image_Cached`` Image_Cached
`public string` | # `cacheFilename( string $format, string $arg1 = null, string $arg2 = null )` Return the filename for the cached image, given it's format name and arguments. Return the filename for the cached image, given it's format name and arguments. #### Parameters $format string $format The format name. $arg1 string $arg1 The first argument passed to the generate function. $arg2 string $arg2 The second argument passed to the generate function. #### Returns `string` string
`public` | # `generateFormattedImage( string $format, string $arg1 = null, string $arg2 = null )` Generate an image on the specified format. It will save the image at the location specified by cacheFilename(). The image will be generated using the specific 'generate' method for the specified format. Generate an image on the specified format. It will save the image at the location specified by cacheFilename(). The image will be generated using the specific 'generate' method for the specified format. #### Parameters $format string $format Name of the format to generate. $arg1 string $arg1 Argument to pass to the generate method. $arg2 string $arg2 A second argument to pass to the generate method.
`public` | # `generateResizedImage( mixed $gd, mixed $width, mixed $height )` Generate a resized copy of this image with the given width & height. Use in templates with $ResizedImage. Generate a resized copy of this image with the given width & height. Use in templates with $ResizedImage.
`public` | # `generateCroppedImage( mixed $gd, mixed $width, mixed $height )` Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio. Use in templates with $CroppedImage Generate a resized copy of this image with the given width & height, cropping to maintain aspect ratio. Use in templates with $CroppedImage
`public` | # `generateRotateClockwise( `GD` $gd )` Generate a rotateв Clockwise image Use in templates with $RotateClockwise Generate a rotateв Clockwise image Use in templates with $RotateClockwise
`public` | # `generateRotateCounterClockwise( `GD` $gd )` Generate a rotateв CounterClockwise image Use in templates with $RotateCounterClockwise Generate a rotateв CounterClockwise image Use in templates with $RotateCounterClockwise
`public integer` | # `deleteFormattedImages( )` Remove all of the formatted cached images for this image. Remove all of the formatted cached images for this image. #### Returns `integer` The number of formatted images deleted
`public string|integer` | # `getDimensions( string $dim = "string" )` Get the dimensions of this Image. Get the dimensions of this Image. #### Parameters $dim string $dim If this is equal to "string", return the dimensions in string form, if it is 0 return the height, if it is 1 return the width. #### Returns `string|integer` string|int
`public integer` | # `getWidth( )` Get the width of this image. Get the width of this image. #### Returns `integer` int
`public integer` | # `getHeight( )` Get the height of this image. Get the height of this image. #### Returns `integer` int
`public `Image::ORIENTATION_SQUARE`` | # `getOrientation( )` Get the orientation of this image. Get the orientation of this image. #### Returns ``Image::ORIENTATION_SQUARE`` | ORIENTATION_PORTRAIT | ORIENTATION_LANDSCAPE
`public string` | # `getSVGContent( )` Возвращает содержимое файла Требуется для SVG-формата Возвращает содержимое файла Требуется для SVG-формата #### Returns `string` string
`protected` | # `onBeforeDelete( )` Event handler called before deleting from the database. You can overload this to clean up or otherwise process data before delete this record. Don't forget to call parent::onBeforeDelete(), though! Event handler called before deleting from the database. You can overload this to clean up or otherwise process data before delete this record. Don't forget to call parent::onBeforeDelete(), though! #### Overrides `File::onBeforeDelete`
`protected` | # `resetFilename( mixed $renamePhysicalFile = true )` Change a filename, moving the file if appropriate. Change a filename, moving the file if appropriate. #### Parameters $renamePhysicalFile $renamePhysicalFile Set this to false if you don't want to rename the physical file. Used when calling resetFilename() on the children of a folder. #### Overrides `File::resetFilename`

### Methods inherited from File

`BackLinkTrackingCount()`, `DeleteLink()`, `Icon()`, `Link()`, `RelativeLink()`, `TreeTitle()`, `appCategory()`, `autosetFilename()`, `canCreate()`, `canDelete()`, `canEdit()`, `canView()`, `collateDescendants()`, `deleteDatabaseOnly()`, `fieldLabels()`, `find()`, `flushCache()`, `format_size()`, `getAbsoluteSize()`, `getAbsoluteURL()`, `getExtension()`, `getFileType()`, `getFilename()`, `getFullPath()`, `getLinkedURL()`, `getRelativePath()`, `getSize()`, `getURL()`, `getUsageCount()`, `get_file_extension()`, `instance_get()`, `onAfterDelete()`, `onAfterUpload()`, `onBeforeWrite()`, `setField()`, `setFilename()`, `setName()`, `setParentID()`, `updateLinks()`, `uploadMetadataFields()`, `validate()`

### Methods inherited from DataObject

`Aggregate()`, `RelationshipAggregate()`, `__construct()`, `baseTable()`, `belongs_to()`, `buildDataObjectSet()`, `buildSQL()`, `can()`, `castedUpdate()`, `composite_fields()`, `context_obj()`, `customDatabaseFields()`, `custom_database_fields()`, `data()`, `databaseFields()`, `databaseIndexes()`, `database_extensions()`, `database_fields()`, `db()`, `dbObject()`, `debug()`, `defaultSearchFilters()`, `delete()`, `delete_by_id()`, `destroy()`, `disableCMSFieldsExtensions()`, `disable_subclass_access()`, `duplicate()`, `enableCMSFieldsExtensions()`, `enable_subclass_access()`, `extendedSQL()`, `fieldLabel()`, `flush_and_destroy_cache()`, `forceChange()`, `get()`, `getAllFields()`, `getCMSActions()`, `getCMSFields()`, `getChangedFields()`, `getClassAncestry()`, `getComponent()`, `getComponents()`, `getComponentsQuery()`, `getDefaultSearchContext()`, `getField()`, `getFrontEndFields()`, `getManyManyComponents()`, `getManyManyComponentsQuery()`, `getManyManyFilter()`, `getManyManyJoin()`, `getRemoteJoinField()`, `getReverseAssociation()`, `getTitle()`, `get_by_id()`, `get_one()`, `get_validation_enabled()`, `hasDatabaseField()`, `hasField()`, `hasOwnTableDatabaseField()`, `hasValue()`, `has_many()`, `has_one()`, `has_own_table()`, `i18n_plural_name()`, `i18n_singular_name()`, `inheritedDatabaseFields()`, `instance_get_one()`, `isChanged()`, `isEmpty()`, `isInDB()`, `is_composite_field()`, `many_many()`, `many_many_extraFields()`, `merge()`, `newClassInstance()`, `onAfterWrite()`, `plural_name()`, `populateDefaults()`, `provideI18nEntities()`, `relObject()`, `requireDefaultRecords()`, `requireTable()`, `reset()`, `scaffoldFormFields()`, `scaffoldSearchFields()`, `searchableFields()`, `setCastedField()`, `setClassName()`, `setComponent()`, `set_context_obj()`, `set_validation_enabled()`, `singular_name()`, `summaryFields()`, `toMap()`, `update()`, `write()`, `writeComponents()`, `writeWithoutVersion()`

### Methods inherited from ViewableData

`ATT_val()`, `BaseHref()`, `CSSClasses()`, `ColumnBreak()`, `ColumnCalc()`, `ColumnNumber()`, `ColumnPad()`, `ColumnPos()`, `CurrentMember()`, `CurrentPage()`, `Debug()`, `Even()`, `EvenOdd()`, `First()`, `FirstLast()`, `HasPerm()`, `IsAjax()`, `JS_val()`, `Last()`, `Me()`, `Middle()`, `MiddleString()`, `Modulus()`, `MultipleOf()`, `Odd()`, `Pos()`, `RAW_val()`, `SQL_val()`, `ThemeDir()`, `ThemeName()`, `Top()`, `TotalItems()`, `XML_val()`, `__get()`, `__isset()`, `__set()`, `buildCastingCache()`, `cachedCall()`, `castingClass()`, `castingHelper()`, `castingHelperPair()`, `castingObjectCreator()`, `castingObjectCreatorPair()`, `customise()`, `escapeTypeForField()`, `getIterator()`, `getSecurityID()`, `getXMLValues()`, `i18nLocale()`, `iteratorProperties()`, `obj()`, `renderWith()`, `setCustomisedObj()`

### 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()`, `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

## Constants summary

`integer` | `ORIENTATION_SQUARE` | `0` | #
`integer` | `ORIENTATION_PORTRAIT` | `1` | #
`integer` | `ORIENTATION_LANDSCAPE` | `2` | #

## Properties summary

`public static array` | $casting | # Use a casting object for a field. This is a map from field name to class name of the casting object. Use a casting object for a field. This is a map from field name to class name of the casting object.
`public static array` | $safeGenerateFormats | #
`public static integer` | $strip_thumbnail_width | # The width of an image thumbnail in a strip. The width of an image thumbnail in a strip.
`public static integer` | $strip_thumbnail_height | # The height of an image thumbnail in a strip. The height of an image thumbnail in a strip.
`public static integer` | $cms_thumbnail_width | # The width of an image thumbnail in the CMS. The width of an image thumbnail in the CMS.
`public static integer` | $cms_thumbnail_height | # The height of an image thumbnail in the CMS. The height of an image thumbnail in the CMS.
`public static integer` | $asset_thumbnail_width | # The width of an image thumbnail in the Asset section. The width of an image thumbnail in the Asset section.
`public static integer` | $asset_thumbnail_height | # The height of an image thumbnail in the Asset section. The height of an image thumbnail in the Asset section.
`public static integer` | $asset_preview_width | # The width of an image preview in the Asset section. The width of an image preview in the Asset section.
`public static integer` | $asset_preview_height | # The height of an image preview in the Asset section. The height of an image preview in the Asset section.
`public static integer` | $asset_popup_size | # Height and width of an asset in a popup Height and width of an asset in a popup

### Properties inherited from File

`$allowed_extensions`, `$apply_restrictions_to_admin`, `$belongs_many_many`, `$cache_file_fields`, `$db`, `$default_sort`, `$defaults`, `$extensions`, `$has_many`, `$has_one`, `$indexes`, `$many_many`, `$plural_name`, `$singular_name`

### Properties inherited from DataObject

`$allowed_actions`, `$ancestry`, `$api_access`, `$belongs_to`, `$brokenOnDelete`, `$brokenOnWrite`, `$cache_get_one`, `$cache_has_own_table`, `$cache_has_own_table_field`, `$componentCache`, `$components`, `$create_table_options`, `$default_records`, `$destroyed`, `$field_labels`, `$many_many_extraFields`, `$original`, `$record`, `$searchable_fields`, `$summary_fields`

### Properties inherited from ViewableData

`$customisedObject`, `$default_cast`, `$failover`, `$iteratorPos`, `$iteratorTotalItems`

### Properties inherited from Object

`$class`, `$extension_instances`

[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. -