PhotoEdit

This class wraps some handy methods for editing photos. Supported file formats are: jpg, png, gif, bmp, cod, ief, jfif tif, ras, cmx, ico, pnm, pbm, pgm, ppm, rgb, xbm, xpm, xwd, jps, fh.
Source
PhotoEdit.php
Depends on
PhotoEditError

Properties

errors = array

$obj->errors = array()

When throw exceptions is set to false the exceptions will be put into this array, the exceptions will be constants defined in "PhotoEdit".

Static Methods

imagecreatefrombmp

resource PhotoEdit::imagecreatefrombmp(string filename)

Create image from bmp file.

Arguments

    filename (string)
    Path to a bmp image file

Returns

resource
Image

isPhoto

bool PhotoEdit::isPhoto(string filename)

To check if a file is a valid image file or not.

Arguments

    filename (string)
    Image file-path to be checked

Returns

bool
true=is a valid image

Methods

__construct

PhotoEdit $obj = new PhotoEdit(bool | string filename=null, bool throw=true)

Construct object. If filename is passed then load the image for editing.

Arguments

    filename=null (bool | string)
    Path to an image file to be load when constructing object, null=load images using "PhotoEdit.load()", bool=throw (considered as value for the second argument)
    throw=true (bool)
    true=on error throw exception, false=dont throw exceptions but put errors in the "errors" property

Returns

void

Throws

__destruct

__destruct()

Clean up resources.

Returns

void

checkType

bool $obj->checkType(string | [string] | array type=jpg)

Checks if the loaded image type is between the given type list.

Arguments

    type=jpg (string | [string] | array)
    File Type(s) to be checked against

Returns

bool
true=file type is between the known list

convert

PhotoEdit $obj->convert(string type='jpg', string filename=null, int quality=-1)

Convert file format.
If filename is provided then the file will be saved immediately without calling "save()"

Arguments

    type='jpg' (string)
    The new file format
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

crop

PhotoEdit $obj->crop(
    int left,
    int top,
    int cropWidth,
    int cropHeight,
    string filename=null,
    int quality=-1
)

Crop the image by starting point and crop width/height.
If filename is provided then the file will be saved immediately without calling "save()"

Since
Artaengine 1.2.0

Arguments

    left (int)
    Starting point x
    top (int)
    Starting point y
    cropWidth (int)
    Crop width
    cropHeight (int)
    Crop height
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

cropX

PhotoEdit $obj->cropX(
    int left,
    int top,
    int right,
    int bottom,
    string filename=null,
    int quality=-1
)

Crop image from starting from one point ending at another point.
If filename is provided then the file will be saved immediately without calling "save()"

Since
Artaengine 1.2.0

Arguments

    left (int)
    Starting point x
    top (int)
    Starting point y
    right (int)
    Ending point x
    bottom (int)
    Ending point y
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

getHeight

int $obj->getHeight(string file=null)

Get image height.

Arguments

    file=null (string)
    Image file-path, null=use the opened image

Returns

int
Image height

getMimeType

string $obj->getMimeType(string filename=null)

Image mime file type.

Arguments

    filename=null (string)
    Image file-path to get type, null=use opened file

Returns

string
Mime type

getType

string $obj->getType(string filename=null)

Image file type.

Arguments

    filename=null (string)
    Image file-path to get type, null=use opened file

Returns

string
File type, a string such as 'jpg' or 'png'

getWidth

int $obj->getWidth(string file=null)

Get image width.

Arguments

    file=null (string)
    Image file-path, null=use the opened image

Returns

int
Image width

isThisPhoto

bool $obj->isThisPhoto()

To check if the opened file is a valid image file or not.

Returns

bool
true=is a valid image

load

PhotoEdit $obj->load(string filename=null)

Load an image for editing. After this method loads the image successfully, the edit methods can be called to alter the image.

Arguments

    filename=null (string)
    Path to an image file to be loaded. null=load the previous loaded image file again

Returns

PhotoEdit
For method chaining

Throws

resize

PhotoEdit $obj->resize(int newW, int newH=0, string filename=null, int quality=-1)

Resize the image. If one of newH and newW is zero the resized image will keep the original aspect ratio.
If filename is provided then the file will be saved immediately without calling "save()"

Arguments

    newW (int)
    New width in pixels. If newH=0, newH will be calculated
    newH=0 (int)
    New height in pixels. If newW=0, newW will be calculated
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

resizeCrop

PhotoEdit $obj->resizeCrop(int newW, int newH, string filename=null, int quality=-1)

Resize the image with respecting the original aspect ratio. if the new size does not respect the original ratio then the image will be cropped.
If filename is provided then the file will be saved immediately without calling "save()"

Arguments

    newW (int)
    New width in pixels
    newH (int)
    New height in pixels
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

resizeLarger

PhotoEdit $obj->resizeLarger(
    int newW,
    int newH=0,
    string filename=null,
    int quality=-1
)

Resize image only if the new image will be smaller. If one of newH and newW is zero the resized image will keep the original aspect ratio.
If filename is provided then the file will be saved immediately without calling "save()"

Since
Artaengine 1.2.0

Arguments

    newW (int)
    New width in pixels. If newH=0, newH will be calculated
    newH=0 (int)
    New height in pixels. If newW=0, newW will be calculated
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

save

PhotoEdit $obj->save(string filename=null, int quality=-1)

Save the edited image to a file.

Arguments

    filename=null (string)
    string=file-path to write the image to, null=overwrite on the opened image
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

watermark

PhotoEdit $obj->watermark(
    string stamp,
    int x=0,
    int y=0,
    string filename=null,
    int quality=-1
)

Watermark with another image.
If filename is provided then the file will be saved immediately without calling "save()"

Arguments

    stamp (string)
    File-path to the watermark image file
    x=0 (int)
    x(left) pixel to position the watermark at
    y=0 (int)
    y(top) pixel to position the watermark at
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining

watermarkText

PhotoEdit $obj->watermarkText(
    string stamp,
    int x=0,
    int y=0,
    string font='arial.ttf',
    number fontSize=10,
    string filename=null,
    int quality=-1
)

Watermark an image with text.
If filename is provided then the file will be saved immediately without calling "save()"

Arguments

    stamp (string)
    Watermark text
    x=0 (int)
    x(left) pixel to position the watermark at
    y=0 (int)
    y(top) pixel to position the watermark at
    font='arial.ttf' (string)
    Font file-name
    fontSize=10 (number)
    Font-size
    filename=null (string)
    Image file-path to save the changes to
    quality=-1 (int)
    png: 0-9, jpeg: 0-100 and -1=highest quality

Returns

PhotoEdit
For method chaining