![]() |
|
Image wrapper. Offers support between image-format conversions, resizing, watermarking and quality management. More...
Public Member Functions | |
Image ($image) | |
getWidth () | |
getHeight () | |
getType () | |
resource () | |
saveAs ($file, $type=null, $quality=null) | |
scale ($scale) | |
resize ($width, $height, $constrain=true, $sharpen=true) | |
mergeWith (Image $image, $this_x=0, $this_y=0, $image_x=0, $image_y=0, $image_width=null, $image_height=null, $opacity=50) | |
close () | |
__destruct () | |
Data Fields | |
$default_quality = 90 | |
$type | |
$source | |
$height | |
$width | |
Image wrapper. Offers support between image-format conversions, resizing, watermarking and quality management.
Creating an object is done by passing an image path to the constructor
Width and height of the image can be optained by the following getter methods :
For custom processing, the php image resource can be obtained :
Resizing can be done by either scaling the image, or resizing it according to a set width or height.
When resizing by a set size, the original proportions of the image can be kept, and resizing the image will be based either on the width, or on the height, depending which one is bigger. Sharpening while resizing will create a higher quality image, but will consume more resorces, so the process might take longer.
Two images can be merged using Image::mergeWidth :
Adding a watermark at the center of an image is done by positioning it's corner relative to its width and height, and relative to the images width and height. Presuming its corner is positioned at (x,y), we need to subtract half of the width and half of the height of the watermark from the center of the image.
The new image can be saved using Image::saveAs :
These methods can also be chained to provide a more readable code :
__destruct | ( | ) |
Destruct
Image | ( | $image | ) |
Constructor
string | $image | : the location of the image |
InvalidFileTypeException | |
FileNotFoundException |
getWidth | ( | ) |
Returns the current width of the image
getHeight | ( | ) |
Returns the current height of the image
getType | ( | ) |
Returns the current type of the image
resource | ( | ) |
Returns the current image resource
saveAs | ( | $file, | |
$type = null , |
|||
$quality = null |
|||
) |
Save the image to a file
string | $file | : file to save to |
string | $type | : optional, the file extension will be used to check the type ( jpeg / png / gif ) |
integer | $quality | : optional, default will be used if none is provided ( [0, 100] ) |
scale | ( | $scale | ) |
Resize the image based on a percentage of the original
int | $scale | : percentage ( [0, 100] ) |
resize | ( | $width, | |
$height, | |||
$constrain = true , |
|||
$sharpen = true |
|||
) |
Resize the image based on width and height
int | $width | : width of the resized image in pixels |
int | $height | : height of the resized image in pixels |
bool | $constrain | : if set to true, the proportions ( image / height )of the original image will be kept |
bool | $sharpen | : set to true in order to sharpen image, but also extend the process of conversion. |
mergeWith | ( | Image | $image, |
$this_x = 0 , |
|||
$this_y = 0 , |
|||
$image_x = 0 , |
|||
$image_y = 0 , |
|||
$image_width = null , |
|||
$image_height = null , |
|||
$opacity = 50 |
|||
) |
Merge another image over this one at a specified position and opacity
Image | $image | |
integer | $this_x | : optional, X-coordinate to merge the image on, default = 0 |
integer | $this_y | : optional, Y-coordinate to merge the image on, default = 0 |
integer | $image_x | : optional, X-coordinate of the merging image, default = 0 |
integer | $image_y | : optional, Y-coordinate of the merging image, default = 0 |
integer | $image_width | : optional, width of the merging image, default = 0 |
integer | $image_height | : optional, height of the merging image, default = 0 |
omteger | $opacity | : optional, the opacity to merge at, default = 50 ( [ 0, 100 ] ) |
close | ( | ) |
Free memory
$default_quality = 90 |
int : Default quality to save the image as ( [0, 100] )
$type |
string : Type of the image ( 'jpeg', 'png', 'gif' )
$source |
resource : Image resource
$height |
int : Width of the image
$width |
int : Height of the image