Represents an image on the filesystem, also provides image manipulation functionality
1.0.0b33 | Fixed a method signature 8/24/11 |
---|---|
1.0.0b32 | Added a call to clearstatcache() to saveChanges() to solve a bug when fFile::output() is called in the same script execution 5/23/11 |
1.0.0b31 | Fixed a bug in using ImageMagick to convert files with a colon in the filename 3/20/11 |
1.0.0b30 | Added a check for systems using the GD extension and no memory limit, plus a check for ImageMagick's convert command failing 3/20/11 |
1.0.0b29 | Added checks for AIX 1/19/11 |
1.0.0b28 | Added the rotate() method, added code to try and prevent fatal errors due to hitting the memory limit when using GD 11/29/10 |
1.0.0b27 | Backwards Compatibility Break - changed the parameter order in crop() from $crop_from_x, $crop_from_y, $new_width, $new_height to $new_width, $new_height, $crop_from_x, $crop_from_y - added $horizontal_position and $vertical_position parameters to cropToRatio() 11/9/10 |
1.0.0b26 | Fixed a bug where processing via ImageMagick was not properly setting the default RGB colorspace 10/19/10 |
1.0.0b25 | Fixed the class to not generate multiple files when saving a JPG from an animated GIF or a TIF with a thumbnail 9/12/10 |
1.0.0b24 | Updated class to use fCore::startErrorCapture() instead of error_reporting() 8/9/10 |
1.0.0b23 | Fixed the class to detect when exec() is disabled and the function has a space before or after in the list 7/21/10 |
1.0.0b22 | Fixed isImageCompatible() to handle certain JPGs created with Photoshop 4/3/10 |
1.0.0b21 | Fixed resize() to allow dimensions to be numeric strings instead of just integers 4/9/10 |
1.0.0b20 | Added append() 3/15/10 |
1.0.0b19 | Updated for the new fFile API 3/5/10 |
1.0.0b18 | Fixed a bug in saveChanges() that would incorrectly cause new filenames to be created, added the $overwrite parameter to saveChanges(), added the $allow_upsizing parameter to resize() 3/3/10 |
1.0.0b17 | Fixed a couple of bug with using ImageMagick on Windows and BSD machines 3/2/10 |
1.0.0b16 | Fixed some bugs with GD not properly handling transparent backgrounds and desaturation of .gif files 10/27/09 |
1.0.0b15 | Added getDimensions() 8/7/09 |
1.0.0b14 | Performance updates for checking image type and compatiblity 7/31/09 |
1.0.0b13 | Updated class to work even if the file extension is wrong or not present, saveChanges() detects files that aren't writable 7/29/09 |
1.0.0b12 | Fixed a bug where calling saveChanges() after unserializing would throw an exception related to the image processor 5/27/09 |
1.0.0b11 | Added a crop() method 5/27/09 |
1.0.0b10 | Fixed a bug with GD not saving changes to files ending in .jpeg 3/18/09 |
1.0.0b9 | Changed processWithGD() to explicitly free the image resource 3/18/09 |
1.0.0b8 | Updated for new fCore API 2/16/09 |
1.0.0b7 | Changed @ error suppression operator to error_reporting() calls 1/26/09 |
1.0.0b6 | Fixed cropToRatio() and resize() to always return the object even if nothing is to be done 1/5/09 |
1.0.0b5 | Added check to see if exec() is disabled, which causes ImageMagick to not work 1/3/09 |
1.0.0b4 | Fixed saveChanges() to not delete the image if no changes have been made 12/18/08 |
1.0.0b3 | Fixed a bug with $jpeg_quality in saveChanges() from 1.0.0b2 12/16/08 |
1.0.0b2 | Changed some int casts to round() to fix resize() dimension issues 12/11/08 |
1.0.0b | The initial implementation 12/19/07 |
fFile | --fImage
Creates an image on the filesystem and returns an object representing it
This operation will be reverted by a filesystem transaction being rolled back.
fImage create( string $file_path, string $contents )
string | $file_path | The path to the new image |
string | $contents | The contents to write to the image |
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Returns an array of acceptable mime types for the processor that was detected
array getCompatibleMimetypes( )
The mime types that the detected image processor can manipulate
Gets the dimensions and type of an image stored on the filesystem
The 'type' key will have one of the following values:
mixed getInfo( string $image_path, string $element=NULL )
string | $image_path | The path to the image to get stats for |
string | $element | The element to retrieve: 'type', 'width', 'height' |
An associative array: 'type' => {mixed}, 'width' => {integer}, 'height' => {integer}, or the element specified
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Checks to make sure the class can handle the image file specified
boolean isImageCompatible( string $image )
string | $image | The image to check for incompatibility |
If the image is compatible with the detected image processor
Please note: this method is public, however it is primarily intended for internal use by Flourish and will normally not be useful in site/application code
Resets the configuration of the class
void reset( )
Sets the directory the ImageMagick binary is installed in and tells the class to use ImageMagick even if GD is installed
void setImageMagickDirectory( string $directory )
string | $directory | The directory ImageMagick is installed in |
Sets a custom directory to use for the ImageMagick temporary files
void setImageMagickTempDir( string $temp_dir )
string | $temp_dir | The directory to use for the ImageMagick temp dir |
Creates an object to represent an image on the filesystem
fImage __construct( string $file_path, boolean $skip_checks=FALSE )
string | $file_path | The path to the image |
boolean | $skip_checks | If file checks should be skipped, which improves performance, but may cause undefined behavior - only skip these if they are duplicated elsewhere |
Prevents a programmer from trying to append an image
void append( mixed $data )
mixed | $data | The data to append to the image |
Crops the image by the exact pixel dimensions specified
The crop does not occur until saveChanges() is called.
fImage crop( numeric $new_width, numeric $new_height, numeric|string $crop_from_x, numeric|string $crop_from_y )
numeric | $new_width | The width in pixels to crop the image to |
numeric | $new_height | The height in pixels to crop the image to |
numeric|string | $crop_from_x | The number of pixels from the left of the image to start the crop from, or a horizontal position of 'left', 'center' or 'right' |
numeric|string | $crop_from_y | The number of pixels from the top of the image to start the crop from, or a vertical position of 'top', 'center' or 'bottom' |
The image object, to allow for method chaining
Crops the biggest area possible from the center of the image that matches the ratio provided
The crop does not occur until saveChanges() is called.
fImage cropToRatio( numeric $ratio_width, numeric $ratio_height, string $horizontal_position='center', string $vertical_position='center' )
numeric | $ratio_width | The width ratio to crop the image to |
numeric | $ratio_height | The height ratio to crop the image to |
string | $horizontal_position | A horizontal position of 'left', 'center' or 'right' |
string | $vertical_position | A vertical position of 'top', 'center' or 'bottom' |
The image object, to allow for method chaining
Converts the image to grayscale
Desaturation does not occur until saveChanges() is called.
fImage desaturate( )
The image object, to allow for method chaining
Returns the width and height of the image as a two element array
array getDimensions( )
In the format 0 => (integer) {width}, 1 => (integer) {height}
Returns the height of the image
integer getHeight( )
The height of the image in pixels
Returns the type of the image
string getType( )
The type of the image: 'jpg', 'gif', 'png', 'tif'
Returns the width of the image
integer getWidth( )
The width of the image in pixels
Sets the image to be resized proportionally to a specific size canvas
Will only size down an image. This method uses resampling to ensure the resized image is smooth in appearance. Resizing does not occur until saveChanges() is called.
fImage resize( integer $canvas_width, integer $canvas_height, boolean $allow_upsizing=FALSE )
integer | $canvas_width | The width of the canvas to fit the image on, 0 for no constraint |
integer | $canvas_height | The height of the canvas to fit the image on, 0 for no constraint |
boolean | $allow_upsizing | If the image is smaller than the desired canvas, the image will be increased in size |
The image object, to allow for method chaining
Sets the image to be rotated
Rotation does not occur until saveChanges() is called.
void rotate( integer $degrees )
integer | $degrees | The number of degrees to rotate - 90, 180, or 270 |
Saves any changes to the image
If the file type is different than the current one, removes the current file once the new one is created.
This operation will be reverted by a filesystem transaction being rolled back. If a transaction is in progress and the new image type causes a new file to be created, the old file will not be deleted until the transaction is committed.
fImage saveChanges( string $new_image_type=NULL, integer $jpeg_quality=90, boolean $overwrite=FALSE )
fImage saveChanges( string $new_image_type=NULL, boolean $overwrite=FALSE )
string | $new_image_type | The new file format for the image: 'NULL (no change), 'jpg', 'gif', 'png'` |
integer | $jpeg_quality | The quality setting to use for JPEG images - this may be ommitted |
boolean | $overwrite | If an existing file with the same name and extension should be overwritten |
The image object, to allow for method chaining