PHP Class Ansel_Image, horde

Copyright 2001-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (GPL). If you did not receive this file, see http://www.horde.org/licenses/gpl.
Author: Chuck Hagenbuch ([email protected])
Author: Michael J. Rubinsky ([email protected])
Inheritance: implements Iterator
Mostrar archivo Open project: horde/horde Class Usage Examples

Public Properties

Property Type Description
$caption string Image caption
$commentCount integer The number of comments for this image, if available.
$facesCount integer Number of faces in this image
$filename string The filename for this image
$gallery integer The gallery id of this image's parent gallery
$geotag_timestamp integer Timestamp for when image was geotagged
$id integer Image Id
$lat string Latitude
$lng string Longitude
$location string Textual location
$originalDate integer Timestamp of original date.
$sort integer Sort count for this image
$type string The image's mime type
$uploaded integer Timestamp of uploaded datetime

Protected Properties

Property Type Description
$_data array Binary image data for loaded views
$_dirty boolean Dirty flag
$_exif array Cache the raw EXIF data locally
$_image Horde_Image_Base Horde_Image object for this image.
$_loaded array Flags for loaded views
$_tags array Holds an array of tags for this image

Public Methods

Method Description
__construct ( array $image = [] ) : Ansel_Image Const'r
addEffect ( string $type, array $params = [] ) Add an effect to the effect stack
applyEffects ( ) Apply any pending effects to the underlaying Horde_Image
createView ( string $view, Ansel_Style $style = null, $watermark = '' ) Creates and caches the given view.
crop ( integer $x1, integer $y1, integer $x2, integer $y2 ) Crop this image to desired dimensions. Crops the currently loaded view present in the Horde_Image object.
current ( ) : Ansel_Image Return the current image from the internal iterator.
deleteCache ( string $view = 'all' ) Deletes the specified cache file.
display ( string $view = 'full', Ansel_Style $style = null ) Display the requested view.
downloadHeaders ( string $view = 'full' ) Sends the correct HTTP headers to the browser to download this image.
flip ( string $view = 'full' ) Flips the image.
geotag ( string $lat, string $lng, string $location = '' ) Update the image's geotag data. Saves to backend storage as well, so no need to call self::save()
getAttributes ( ) : array Get the image attributes from the backend.
getDimensions ( string $view = 'full' ) : array Returns the dimensions of the given view.
getEXIF ( boolean $replacing = false ) : boolean Reads the EXIF data from the image, caches in the object and writes to storage. Also populates any local properties that come from the EXIF data.
getHordeImage ( ) : Horde_Image_Base Obtain a reference to the underlying Horde_Image
getImagePageCount ( ) : integer Get the number of pages that a multipage image contains.
getTags ( ) : array Returns this image's tags.
getTile ( Ansel_Gallery $parent = null, Ansel_Style $style = null, boolean $mini = false, array $params = [] ) : string Get the Ansel_View_Image_Thumb object
getType ( $view = 'full' ) : string Get the image type for the requested view.
getVFSName ( string $view ) : string Returns the file name of this image as used in the VFS backend.
getVFSPath ( string $view = 'full', Ansel_Style $style = null ) : string Return the vfs path for this image.
getVFSPathFromHash ( string $hash ) : string Generate a path on the VFS given a known style hash.
getViewHash ( string $view, Ansel_Style $style = null ) : string Return a hash key for the given view and style.
grayscale ( string $view = 'full' ) Converts the image to grayscale.
isMultiPage ( ) : boolean Indicates if this image represents a multipage image.
key ( ) : integer Get the index of the internal iterator.
load ( string $view = 'full', Ansel_Style $style = null ) Loads the given view into memory.
mirror ( string $view = 'full' ) Mirrors the image.
next ( ) : mixed Advance the iterator
raw ( string $view = 'full' ) : string Returns the raw data for the given view.
removeTag ( string $tag ) Remove a single tag from this image's tag collection
replace ( array $imageData ) : void Replace this image's image data.
reset ( ) Reset the image, removing all loaded views.
resize ( integer $width, integer $height, boolean $ratio = true, boolean $keepProfile = false ) Resize the current image.
rewind ( ) : void Reset the iterator to the first image in the set.
rotate ( string $view = 'full', integer $angle = 90 ) Rotates the image.
save ( ) : integer Save image details to storage.
setTags ( array $tags, boolean $replace = true ) Either add or replace this image's tags.
toFile ( string $view = 'full' ) : string Wraps the given view into a file.
updateData ( string $data, string $view = 'full' ) Change the image data. Deletes old cache and writes the new data to the VFS. Used when updating an image
valid ( ) : boolean Deterimines if the current iterator item is valid.
viewExists ( integer $id, string $view, Ansel_Style $style ) : mixed Check if an image view exists and returns the vfs name complete with the hash directory name prepended if appropriate.
watermark ( string $view = 'full', string $watermark = null, string $halign = null, string $valign = null, string $font = null ) Watermarks the image.

Protected Methods

Method Description
_autoRotate ( $orientation ) Autorotate based on EXIF orientation field. Updates the data in memory only.
_buildImageObject ( Horde_Image_Base $image ) : Ansel_Image Build an Ansel_Image from a given Horde_Image.
_exifToTags ( array $fields = [] ) : void Adds specified EXIF fields to this image's tags.
_writeData ( ) : boolean Writes the current data to vfs, used when creating a new image

Method Details

__construct() public method

Const'r
public __construct ( array $image = [] ) : Ansel_Image
$image array
return Ansel_Image

_autoRotate() protected method

Autorotate based on EXIF orientation field. Updates the data in memory only.
protected _autoRotate ( $orientation )

_buildImageObject() protected method

Used to wrap iterating the Horde_Image
protected _buildImageObject ( Horde_Image_Base $image ) : Ansel_Image
$image Horde_Image_Base The Horde_Image
return Ansel_Image

_exifToTags() protected method

Called during image upload/creation.
protected _exifToTags ( array $fields = [] ) : void
$fields array An array of EXIF fields to import as a tag.
return void

_writeData() protected method

Writes the current data to vfs, used when creating a new image
protected _writeData ( ) : boolean
return boolean

addEffect() public method

Add an effect to the effect stack
public addEffect ( string $type, array $params = [] )
$type string The effect to add.
$params array The effect parameters.

applyEffects() public method

Apply any pending effects to the underlaying Horde_Image
public applyEffects ( )

createView() public method

Creates and caches the given view.
public createView ( string $view, Ansel_Style $style = null, $watermark = '' )
$view string Which view to create.
$style Ansel_Style A style object

crop() public method

Crop this image to desired dimensions. Crops the currently loaded view present in the Horde_Image object.
See also: Horde_Image_Base::crop for explanation of parameters
public crop ( integer $x1, integer $y1, integer $x2, integer $y2 )
$x1 integer
$y1 integer
$x2 integer
$y2 integer

current() public method

Return the current image from the internal iterator.
public current ( ) : Ansel_Image
return Ansel_Image

deleteCache() public method

If none is specified, deletes all of the cache files.
public deleteCache ( string $view = 'all' )
$view string Which cache file to delete.

display() public method

Display the requested view.
public display ( string $view = 'full', Ansel_Style $style = null )
$view string Which view to display.
$style Ansel_Style Force use of this gallery style.

downloadHeaders() public method

Sends the correct HTTP headers to the browser to download this image.
public downloadHeaders ( string $view = 'full' )
$view string The view to download.

flip() public method

Flips the image.
public flip ( string $view = 'full' )
$view string The view to work with.

geotag() public method

Update the image's geotag data. Saves to backend storage as well, so no need to call self::save()
public geotag ( string $lat, string $lng, string $location = '' )
$lat string Latitude
$lng string Longitude
$location string Textual location

getAttributes() public method

Get the image attributes from the backend.
public getAttributes ( ) : array
return array A hash of Exif fieldnames => values.

getDimensions() public method

Returns the dimensions of the given view.
public getDimensions ( string $view = 'full' ) : array
$view string The view (full, screen etc..) to get dimensions for
return array A hash of 'width and 'height' dimensions.

getEXIF() public method

Reads the EXIF data from the image, caches in the object and writes to storage. Also populates any local properties that come from the EXIF data.
public getEXIF ( boolean $replacing = false ) : boolean
$replacing boolean Set to true if we are replacing the exif data.
return boolean True if any local properties were modified, False if not.

getHordeImage() public method

Obtain a reference to the underlying Horde_Image
public getHordeImage ( ) : Horde_Image_Base
return Horde_Image_Base

getImagePageCount() public method

Get the number of pages that a multipage image contains.
public getImagePageCount ( ) : integer
return integer The number of pages.

getTags() public method

Returns this image's tags.
See also: Ansel_Tags::readTags()
public getTags ( ) : array
return array An array of tags

getTile() public method

Get the Ansel_View_Image_Thumb object
public getTile ( Ansel_Gallery $parent = null, Ansel_Style $style = null, boolean $mini = false, array $params = [] ) : string
$parent Ansel_Gallery The parent Ansel_Gallery object.
$style Ansel_Style A gallery definition to use.
$mini boolean Force the use of a mini thumbnail?
$params array Any additional parameters the Ansel_Tile object may need.
return string HTML for this image's view tile.

getType() public method

Get the image type for the requested view.
public getType ( $view = 'full' ) : string
return string The requested view's mime type

getVFSName() public method

Returns the file name of this image as used in the VFS backend.
public getVFSName ( string $view ) : string
$view string The image view (full, screen, thumb, mini).
return string This image's VFS file name.

getVFSPath() public method

Return the vfs path for this image.
public getVFSPath ( string $view = 'full', Ansel_Style $style = null ) : string
$view string The view we want.
$style Ansel_Style A gallery style.
return string The vfs path for this image.

getVFSPathFromHash() public method

Generate a path on the VFS given a known style hash.
public getVFSPathFromHash ( string $hash ) : string
$hash string The sytle hash
return string the VFS path to the directory for the provided hash

getViewHash() public method

Return a hash key for the given view and style.
public getViewHash ( string $view, Ansel_Style $style = null ) : string
$view string The view (thumb, prettythumb etc...)
$style Ansel_Style The style.
return string A md5 hash suitable for use as a key.

grayscale() public method

Converts the image to grayscale.
public grayscale ( string $view = 'full' )
$view string The view (screen, full, etc...) to work with.

isMultiPage() public method

Indicates if this image represents a multipage image.
public isMultiPage ( ) : boolean
return boolean

key() public method

Get the index of the internal iterator.
public key ( ) : integer
return integer

load() public method

Loads the given view into memory.
public load ( string $view = 'full', Ansel_Style $style = null )
$view string Which view to load.
$style Ansel_Style The gallery style.

mirror() public method

Mirrors the image.
public mirror ( string $view = 'full' )
$view string The view (size) to work with.

next() public method

Advance the iterator
public next ( ) : mixed
return mixed Ansel_Image or false if not valid()

raw() public method

Returns the raw data for the given view.
public raw ( string $view = 'full' ) : string
$view string Which view to return.
return string The raw binary image data

removeTag() public method

Remove a single tag from this image's tag collection
public removeTag ( string $tag )
$tag string The tag name to remove.

replace() public method

Replace this image's image data.
public replace ( array $imageData ) : void
$imageData array An array of image data, the same keys as Const'r
return void

reset() public method

Reset the image, removing all loaded views.
public reset ( )

resize() public method

Resize the current image.
public resize ( integer $width, integer $height, boolean $ratio = true, boolean $keepProfile = false )
$width integer The new width.
$height integer The new height.
$ratio boolean Maintain original aspect ratio.
$keepProfile boolean Keep the image meta data.

rewind() public method

Reset the iterator to the first image in the set.
public rewind ( ) : void
return void

rotate() public method

Rotates the image.
public rotate ( string $view = 'full', integer $angle = 90 )
$view string The view (size) to work with.
$angle integer What angle to rotate the image by.

save() public method

Save image details to storage.
public save ( ) : integer
return integer image id

setTags() public method

Either add or replace this image's tags.
public setTags ( array $tags, boolean $replace = true )
$tags array An array of tag names
$replace boolean Replace all tags with those provided.

toFile() public method

Wraps the given view into a file.
Deprecation: Not used anywhere, remove in A4.
public toFile ( string $view = 'full' ) : string
$view string Which view to wrap up.
return string Path to temporary file.

updateData() public method

Change the image data. Deletes old cache and writes the new data to the VFS. Used when updating an image
public updateData ( string $data, string $view = 'full' )
$data string The new data for this image.
$view string If specified, the $data represents only this particular view. Cache will not be deleted.

valid() public method

Deterimines if the current iterator item is valid.
public valid ( ) : boolean
return boolean

viewExists() public static method

Check if an image view exists and returns the vfs name complete with the hash directory name prepended if appropriate.
public static viewExists ( integer $id, string $view, Ansel_Style $style ) : mixed
$id integer Image id to check
$view string Which view to check for
$style Ansel_Style Style object
return mixed False if image does not exists | string vfs name

watermark() public method

Watermarks the image.
public watermark ( string $view = 'full', string $watermark = null, string $halign = null, string $valign = null, string $font = null )
$view string The view (size) to work with.
$watermark string String to use as the watermark.
$halign string Horizontal alignment (Left, Right, Center)
$valign string Vertical alignment (Top, Center, Bottom)
$font string The font to use (not all image drivers will support this).

Property Details

$_data protected_oe property

Binary image data for loaded views
protected array $_data
return array

$_dirty protected_oe property

Dirty flag
protected bool $_dirty
return boolean

$_exif protected_oe property

Cache the raw EXIF data locally
protected array $_exif
return array

$_image protected_oe property

Horde_Image object for this image.
protected Horde_Image_Base $_image
return Horde_Image_Base

$_loaded protected_oe property

Flags for loaded views
protected array $_loaded
return array

$_tags protected_oe property

Holds an array of tags for this image
protected array $_tags
return array

$caption public_oe property

Image caption
public string $caption
return string

$commentCount public_oe property

The number of comments for this image, if available.
public int $commentCount
return integer

$facesCount public_oe property

Number of faces in this image
public int $facesCount
return integer

$filename public_oe property

The filename for this image
public string $filename
return string

$geotag_timestamp public_oe property

Timestamp for when image was geotagged
public int $geotag_timestamp
return integer

$id public_oe property

Image Id
public int $id
return integer

$lat public_oe property

Latitude
public string $lat
return string

$lng public_oe property

Longitude
public string $lng
return string

$location public_oe property

Textual location
public string $location
return string

$originalDate public_oe property

Timestamp of original date.
public int $originalDate
return integer

$sort public_oe property

Sort count for this image
public int $sort
return integer

$type public_oe property

The image's mime type
public string $type
return string

$uploaded public_oe property

Timestamp of uploaded datetime
public int $uploaded
return integer