UNA
Loading...
Searching...
No Matches
BxDolTranscoderImage Class Reference
Inheritance diagram for BxDolTranscoderImage:
BxDolTranscoder iBxDolFactoryObject BxDolFactory iBxDolFactoryObject

Public Member Functions

 isMimeTypeSupported ($sMimeType)
 
 getFileUrl ($mixedHandler)
 
 getFileMimeType ($mixedHandler)
 
 getFileUrlNotReady ($mixedHandler)
 
 isFileReady ($mixedHandlerOrig, $isCheckOutdated=true)
 
 getSize ($sFile)
 
 transcode ($mixedHandler, $iProfileId=0)
 
- Public Member Functions inherited from BxDolTranscoder
 onDeleteFileLocal ($iFileId)
 
 onDeleteFileOrig ($mixedHandler)
 
 registerHandlers ()
 
 unregisterHandlers ()
 
 cleanup ()
 
 getStorage ()
 
 getDb ()
 
 getFileUrlById ($mixedHandler)
 
 prune ()
 
 forceDevicePixelRatio ($i)
 
 getDevicePixelRatio ()
 
 getOrigFileUrl ($mixedHandler)
 
 getTmpFilename ($sOverrideName=false)
 
 clearLog ()
 
 addToLog ($s)
 
 getLog ()
 
 deleteFromQueue ($mixedHandler)
 
 storeTranscodedFile ($mixedHandler, $sTmpFile, $iProfileId)
 
 getDevicePixelRatioHandlerSuffix ()
 
 getFilterParams ($sName)
 
 getMaxResizeDimention ($sFilter='Resize', $sKey='')
 
 isMobile ()
 

Static Public Member Functions

static getObjectAbstract ()
 
- Static Public Member Functions inherited from BxDolTranscoder
static getObjectInstance ($sObject)
 
static pruning ()
 
static processQueue ($bQueuePruning=true)
 
static pruneQueue ()
 
static processCompleted ()
 
static registerHandlersArray ($mixed)
 
static registerHandlersSystem ()
 
static unregisterHandlersArray ($mixed)
 
static cleanupObjectsArray ($mixed)
 
static onAlertResponseFileDeleteLocal ($oAlert, $sObject)
 
static onAlertResponseFileDeleteOrig ($oAlert, $sObject)
 

Protected Member Functions

 __construct ($aObject, $oStorage)
 
 getCustomResizeDimension ($sName)
 
 applyFilter_Grayscale ($sFile, $aParams)
 
 applyFilter_ResizeVar ($sFile, $aParams)
 
- Protected Member Functions inherited from BxDolTranscoder
 storeTranscodedFileInQueueStorage ($mixedHandler, $sTmpFile, &$sFileUrlResult)
 
 addToQueue ($mixedHandler, $iProfileId=0)
 
 applyFilter_Resize ($sFile, $aParams)
 
 isFileReady_Folder ($mixedHandlerOrig, $isCheckOutdated=true)
 
 isFileReady_Storage ($mixedHandlerOrig, $isCheckOutdated=true)
 
 isPrivate_Folder ($mixedHandler)
 
 isPrivate_Storage ($mixedHandler)
 
 getFilePath_Folder ($mixedHandler)
 
 storeFileLocally_Folder ($mixedHandler)
 
 storeFileLocally_Storage ($mixedHandler)
 
 storeFileLocally_Queue ($mixedHandler)
 
 getOrigFileUrl_Folder ($mixedHandler)
 
 getOrigFileUrl_Storage ($mixedHandler)
 
 initFilters ()
 
 clearCacheDB ()
 
 processHandlerForRetinaDevice ($mixedHandler)
 

Additional Inherited Members

- Static Protected Member Functions inherited from BxDolTranscoder
static getTranscoderObjects ()
 
static _callFuncForObjectsArray ($mixed, $sFunc)
 
- Protected Attributes inherited from BxDolTranscoder
 $_sLog = ''
 
 $_aObject
 
 $_oStorage
 
 $_oDb
 
 $_sRetinaSuffix = '@2x'
 
 $_sQueueTable = ''
 
 $_sQueueStorage = ''
 
 $_iDevicePixelRatio = false
 

Detailed Description

This class transcodes images on the fly. Transcoded image is saved in the specified storage engine and next time ready image is served.

To add image transcoder object add record to 'sys_objects_transcoder' table:

  • object - name of the transcoder object, in the format: vendor prefix, underscore, module prefix, underscore, image size name; for example: bx_images_thumb.
  • storage_object - name of the storage object to store transcoded data, the specified storage object need to be created too,
    See also
    BxDolStorage.
  • source_type - type of the source, where is source image is taken from, available options 'Storage' and 'Folder' for now.
  • source_params - source_type params, each source_type can have own set of params, please read futher for more info about particular source_types, serialized array of params is stored here.
  • private - how to store transcoded data:
    • no - store transcoded data publicly.
    • yes - store transcoded data privately.
    • auto - detect automatically, not supported for 'Folder' source type.
  • atime_tracking - track last access time to the transcoded data, allowed values 0 - disables or 1 - enabled.
  • atime_pruning - prune transcoded images by last access time, if last access time of the image is older than atime_pruning seconds - it is deleted, it works when atime_tracking is enabled
  • ts - unix timestamp of the last change of transcoder parameters, if transcoded image is older than this value - image is deleted and transcoded again.

Then you need to add image filters to 'sys_transcoder_filters' table:

  • transcoder_object - name of the transcoded object to apply filter to.
  • filter - filter name, please read futher for available filters.
  • filter_params - serialized array of filter params, please read futher for particular filters params.
  • order - if there are several filters for one object, they will be applied in this order.

'Folder' source types: This source type is some folder with original images for the transcoding, the identifier of the image (handler) is file name. The params are the following:

  • path - path to the folder with original images This source type has some limitation:
  • automatic detection of private files is not supported
  • transcoded file is not automaticlaly deleted/renewed if original file is changed

'Storage' source type: The source of original files is Storage engine, the identifier of the image (handler) is file id. The params are the following:

  • object - name of the Storage object

Available filters:

  • Resize - this filter resizes original image, the parameters are the following:
    • w - width of resulted image.
    • h - height of resulted image.
    • square_resize - make resulted image square, even of original image is not square, 'w' and 'h' parameters must be the same.
    • crop_resize - crop image to destination size with filling whole area of destination size.
    • force_type - always change type of the image to the specified type: jpg, png, gif.
  • Grayscale - make image grayscale, there is no parameters for this filter

Automatic deletetion of associated data is supported - in the case if original or transcoded file is deleted, but you need to register alert handlers, just call registerHandlers () function to register handler (for example, during module installation) and call unregisterHandlers () function to unregister handlers (for example, during module uninstallation)

Example of usage:

$oTranscoder = BxDolTranscoderImage::getObjectInstance('bx_images_thumb'); // change images transcode object name to your own
$oTranscoder->registerHandlers(); // make sure to call it only once! before the first usage, no need to call it every time
$sTranscodedImageUrl = $oTranscoder->getFileUrl('my_dog.jpg'); // the name of file, in the case of 'Folder' storage type this is file name
echo 'My dog : <img src="' . $sUrl . '" />'; // transcoded(resized and/or grayscaled) image will be shown, according to the specified filters
static getObjectInstance($sObject)
Definition BxDolTranscoder.php:52

Constructor & Destructor Documentation

◆ __construct()

BxDolTranscoderImage::__construct ( $aObject,
$oStorage )
protected

constructor

Reimplemented from BxDolTranscoder.

Member Function Documentation

◆ getFileUrl()

BxDolTranscoderImage::getFileUrl ( $mixedHandler)

Get transcoded file url. If transcoded file is ready then direct url to the file is returned. If there is no transcoded data available, then special url is returned, upon opening this url image is transcoded automatically and redirects to the ready transcoed image.

Parameters
$mixedHandler- file handler
Returns
file url, or false on error.

Reimplemented from BxDolTranscoder.

◆ getFileUrlNotReady()

BxDolTranscoderImage::getFileUrlNotReady ( $mixedHandler)

Get file url when file isn't transcoded yet

Reimplemented from BxDolTranscoder.

◆ isFileReady()

BxDolTranscoderImage::isFileReady ( $mixedHandler,
$isCheckOutdated = true )

Check if transcoded data is available. No need to call it directly, it is called automatically when it is needed.

Parameters
$mixedHandler- file handler
$isCheckOutdated- check if transcoded file is outdated
Returns
false if there is no ready transcoded file is available or it is outdated, true if file is ready

Reimplemented from BxDolTranscoder.

◆ isMimeTypeSupported()

BxDolTranscoderImage::isMimeTypeSupported ( $sMimeType)

check if transcoder suppors given file mime type

Reimplemented from BxDolTranscoder.

◆ transcode()

BxDolTranscoderImage::transcode ( $mixedHandler,
$iProfileId = 0 )

Transcode file, no need to call it directly, it is called automatically when it is needed.

Parameters
$mixedHandler- file handler
$iProfileId- optional profile id, to assign transcoded file ownership to, usually it is NOT assigned to any particular profile, so just leave it default
Returns
true on success, false on error

Hooks:

'system', 'transcode' - hook before file is transcoded

  • $unit_name - equals system
  • $action - equals transcode
  • $object_id - file handler
  • $sender_id - equals false
  • $extra_params - array of additional params with the following array keys:

Hooks:

'system', 'transcoded' - hook after file is transcoded

  • $unit_name - equals system
  • $action - equals transcoded
  • $object_id - file handler
  • $sender_id - equals false
  • $extra_params - array of additional params with the following array keys:

Reimplemented from BxDolTranscoder.


The documentation for this class was generated from the following file: