FileTransform
in package
Methods for file resizing
Table of Contents
Methods
- addTransformRecord() : FileTransformModel
- Add a transform record to the data store
- createDefaultTransform() : bool
- Create a specific default image size, as per the config parameter 'file.image_transformations'
- createDefaultTransforms() : array<string|int, bool>
- Create default image sizes as per the config parameter 'file.image_transformations'
- createInstantTransforms() : array<string|int, bool>
- Create default image sizes as per the config parameter 'file.image_transformations_instant'
- createTransformSize() : bool
- Create transformed image for a single resize.
- createTransformSizes() : array<string|int, bool>
- Create default image sizes as per the specified array of sizes'
- deleteByFileId() : bool
- Delete a given transform file and db record by its ID
- deleteByFilename() : bool
- Delete a given transform file and db record by its filename
- deleteById() : bool
- Delete a file transform by its record ID
- deleteTransforms() : mixed
- Delete transformed versions of a file
- findByFileId() : FileTransformModel|null
- Look for a transform table entry for a file by its ID
- findByFilename() : FileTransformModel|null
- Look for a transform table entry for a file by the filename
- getById() : FileTransformModel|null
- Get a file transform by its record ID
- getByTransformFilename() : FileTransformModel|null
- Get a file transform by its transform filename
- getTransformFilename() : string
- Create a predictable filename for a given file/transform combo.
- getTransforms() : array<string|int, mixed>
- Returns a list of files transforms stored in the database
- resizeImage() : bool
- Resize an image to a given size spec
Methods
addTransformRecord()
Add a transform record to the data store
public
static addTransformRecord(int $file_id, string $filename, string $transform_name, string $transform_filename, array<string|int, mixed>|string $imgsize, int $filesize[, string|null $backend_type = null ]) : FileTransformModel
Parameters
- $file_id : int
-
The original file ID (or 0 if not known) that has been transformed
- $filename : string
-
The original filename that has been transformed
- $transform_name : string
-
The transform string e.g. 'c400x200'
- $transform_filename : string
-
The filename of the transformed file
- $imgsize : array<string|int, mixed>|string
-
Array output from imgsize (opt. json encoded) or empty string
- $filesize : int
- $backend_type : string|null = null
Return values
FileTransformModelcreateDefaultTransform()
Create a specific default image size, as per the config parameter 'file.image_transformations'
public
static createDefaultTransform(string|int $filename_or_id, string $specific_size) : bool
Parameters
- $filename_or_id : string|int
- $specific_size : string
Tags
Return values
boolcreateDefaultTransforms()
Create default image sizes as per the config parameter 'file.image_transformations'
public
static createDefaultTransforms(int $file_id) : array<string|int, bool>
Parameters
- $file_id : int
-
The file to create sizes for
Return values
array<string|int, bool> —[ size => bool ]
createInstantTransforms()
Create default image sizes as per the config parameter 'file.image_transformations_instant'
public
static createInstantTransforms(int $file_id) : array<string|int, bool>
Parameters
- $file_id : int
-
The file to create sizes for
Return values
array<string|int, bool> —[ size => bool ]
createTransformSize()
Create transformed image for a single resize.
public
static createTransformSize(string|int $filename_or_id, string $size_name, ResizeImageTransform $size[, string|null $file_backend_type = null ]) : bool
Parameters
- $filename_or_id : string|int
- $size_name : string
- $size : ResizeImageTransform
- $file_backend_type : string|null = null
Tags
Return values
boolcreateTransformSizes()
Create default image sizes as per the specified array of sizes'
public
static createTransformSizes(string|int $filename_or_id, array<string|int, array<string|int, ResizeImageTransform>> $sizes[, string|null $specific_size = null ][, string|null $file_backend_type = null ]) : array<string|int, bool>
Parameters
- $filename_or_id : string|int
-
The file to create sizes for
- $sizes : array<string|int, array<string|int, ResizeImageTransform>>
-
[ name => [transforms] ]
- $specific_size : string|null = null
-
Optional parameter to process only a single size
- $file_backend_type : string|null = null
-
Optional parameter to specify a different file backend
Tags
Return values
array<string|int, bool> —[ size => bool ]
deleteByFileId()
Delete a given transform file and db record by its ID
public
static deleteByFileId(int $file_id, string $transform_name) : bool
Parameters
- $file_id : int
-
The base file ID we want to delete
- $transform_name : string
-
The filesize string e.g. 'c400x200'
Return values
booldeleteByFilename()
Delete a given transform file and db record by its filename
public
static deleteByFilename(string $filename, string $transform_name) : bool
If we don't have a record, we'll try a direct delete of the transform filename
Parameters
- $filename : string
-
The base filename we want to delete
- $transform_name : string
-
The filesize string e.g. 'c400x200'
Return values
booldeleteById()
Delete a file transform by its record ID
public
static deleteById(int $transform_id) : bool
Parameters
- $transform_id : int
Return values
booldeleteTransforms()
Delete transformed versions of a file
public
static deleteTransforms(string|int $filename_or_id) : mixed
If passed an id, this will try and load stored data from the record It may be passed a filename however for legacy/direct processing support
Parameters
- $filename_or_id : string|int
-
The name of the file in the repository
findByFileId()
Look for a transform table entry for a file by its ID
public
static findByFileId(int $file_id, string $transform_name) : FileTransformModel|null
Parameters
- $file_id : int
-
The ID of the file we're looking for
- $transform_name : string
-
The filesize string e.g. 'c400x200'
Return values
FileTransformModel|nullfindByFilename()
Look for a transform table entry for a file by the filename
public
static findByFilename(string $filename, string $transform_name) : FileTransformModel|null
If not found, this will attempt to find matching file details in the files table If we have these, we'll try and ID lookup
Parameters
- $filename : string
-
The name of the file (no path) we're looking for
- $transform_name : string
-
The transform string e.g. 'c400x200'
Return values
FileTransformModel|nullgetById()
Get a file transform by its record ID
public
static getById(int $transform_id) : FileTransformModel|null
Parameters
- $transform_id : int
Return values
FileTransformModel|nullgetByTransformFilename()
Get a file transform by its transform filename
public
static getByTransformFilename(string $transform_filename) : FileTransformModel|null
Parameters
- $transform_filename : string
Return values
FileTransformModel|nullgetTransformFilename()
Create a predictable filename for a given file/transform combo.
public
static getTransformFilename(string $filename, string $transform_name[, string|null $force_ext = null ][, string|null $force_backend = null ]) : string
This will use the folder prefix for the currently active backend
Parameters
- $filename : string
-
The name of the file (no path) we're looking for
- $transform_name : string
-
The transform string e.g. 'c400x200'
- $force_ext : string|null = null
-
If set, extension is set to this
- $force_backend : string|null = null
-
A backend to force config from, e.g. 's3' or 'local'
Return values
string —Name of resized file, e.g. 123_example.c400x200.jpg
getTransforms()
Returns a list of files transforms stored in the database
public
static getTransforms(string|int $filename_or_id) : array<string|int, mixed>
If passed an id, this will try and load stored data from the record It may be passed a filename however for legacy/direct processing support
Parameters
- $filename_or_id : string|int
-
The name of the file in the repository
Return values
array<string|int, mixed> —An array of file transform records
resizeImage()
Resize an image to a given size spec
public
static resizeImage(string $filepath, string $size[, string|null $embed_text = null ][, array<string|int, mixed>|null $focal_points = [] ]) : bool
This avoids using any File helpers that might use remote backend functions This is to allow the tooling to be used as needed on any temp/local images
Parameters
- $filepath : string
-
Full (local) file path to the image to be resized
- $size : string
-
Size string as per the File::parseSizeString() method.
- $embed_text : string|null = null
-
Text to embed in the image, if any.
- $focal_points : array<string|int, mixed>|null = []
-
Focal points for cropping, if any.
Tags
Return values
bool —Flag for success/fail