Open-Source PHP Framework - Designed for rapid development of performance-oriented scalable applications

File component

API >> mvc >> components >> file

getImageSize($src)

Get the dimensions of an image file, results are cached in the $this->files array and are indexed by $src. You can retrieve the values of an image from this array at any future time within the instance. Return is an array on success, Boolean false on failure.

getImageFormat($src)

Get the format (gif, jpeg, etc.) of an image file. Return is a string for standard image types, int for non-standard, boolean false on failure.

isInvalidUpload($id, $imagesOnly = false)

Checks if an uploaded file has or has not been successfully uploaded and is in the expected format. Returns Boolean false if valid, error message string if invalid.

uploadFile($id, $destination, $imagesOnly = false)

Validates and then moves a file that was uploaded from a form. Returns Boolean false on success, an error message string on failure.

resizeImage(array $specs, $src = null)

Resizes an image or generates a set of resized images, optionally adding a watermark to any of them.
Requires the PHP GD extension to be enabled.
$specs array keys:

  • width - required, if constrain is true then this becomes the maximum width
  • height - required, if constrain is true then this becomes the maximum height
  • constrain - (boolean) default is true - resize the image proportionally, if false the end image may be stretched
  • onlyReduce - (boolean) default is true - if true the end image can only be reduced, never be enlarged (which usually degrades quality)
  • outputFolder - folder where to output the file, if omitted the system default will be used
  • outputFile - filename, if omitted the source filename will be used
  • watermark - array with keys:
  • src - required, the path to the watermark image file
  • opacity - Optional, default if omitted is 14

You can also specify generation of multiple output files by setting specs to an array of $specs, eg.:
$specs[] = array('width' => 200'height' => 100'outputFile' => 'thumbnail.jpg'); $specs[] = array('width' => 500'height' => 300'outputFile' => 'bigfile.jpg');
if the $src argument is omitted then the last file added to $this->files will be used, if none exists then this method will exit and return false