Working with images - Jet\Data_Image
This class is intended for working with images in terms of their validation, resizing and previewing.
Overview of methods
Method | Meaning of |
---|---|
public __construct( string $path ) |
Based on the path, the constructor performs a basic check of the image (whether the file exists, is readable and is a supported image type) and retrieves information about the image (image type and dimensions). In case of failure, it throws an exception Jet\Data_Image_Exception. When working with images, it is therefore desirable to enclose the operation in try{}catch. |
public getPath( ) : string |
Returns the full path to the image file. |
public getDirectory( ) : string |
Returns the path to the directory where the image is located. |
public getFileName( ) : string |
Returns the image file name (without directory). |
public getWidth( ) : int |
Returns the width of the image. |
public getHeight( ) : int |
Returns the height of the image. |
public getImgType( ) : int |
Returns the image type number as known and used by PHP. |
public getMimeType( ) : string |
Returns the MIME type of the image. |
public getImageQuality( ) : int |
Sets the image quality for further processing (for image file types where it matters). |
public setImageQuality( int $image_quality ) : void |
Returns the image quality set for further processing. |
public createThumbnail( string $target_path, int $maximal_width, int $maximal_height, ?int $target_img_type=null ) : static |
Creates a preview - a smaller version of the image of the given maximum dimensions with the preserved aspect ratio and saves it to the specified path. The type of the resulting image can be preserved or an adequate PHP constant of the image type can be used. The resulting image is returned as an instance of the Jet\Data_Image class and it is possible to operate on the resulting image immediately. |
public saveAs( string $target_path, ?int $new_width=null, ?int $new_height=null, ?int $target_img_type=null ) : static |
Resizes the image to the specified data (does not handle aspect ratio) and saves it to the specified path. The type of the resulting image can be preserved, or an adequate PHP constant of the image type can be used. The resulting image is returned as an instance of the Jet\Data_Image class and can therefore be manipulated immediately. |