\apex\app\utilsimages

Image Handling Library

Service: apex\svc\images

Class to handle image storage and manipulation, including uploading / adding new images, generating thumbnails, retrieving / storing images, and more.

This class is available within the services container, meaning its methods can be accessed statically via the service singleton as shown below.

PHP Example

<?php

namespace apex;

use apex\app; use apex\svc\images;

// Upload image $product_id = 432; images::upload('product_image', 'product', $product_id);

Summary

Methods
Properties
Constants
add()
upload()
get()
add_thumbnail()
display()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

add()

add(string  $filename, string  $contents, string  $type, mixed  $record_id = '', string  $size = 'full', integer  $is_default) : integer

Add a new image to the database

Parameters

string $filename

The filename of the image

string $contents

The contents of the image

string $type

The type of image (eg. user, product, etc.)

mixed $record_id

Optional record ID to retrieve the image later

string $size

The size of the image, defaults to 'full'.

integer $is_default

int (1/0) that defines whether or not the image is default for this type (eg. default user avatar)

Returns

integer —

The ID# of the new image

upload()

upload(string  $form_field, string  $type, string  $record_id = '', integer  $is_default) : integer

Upload a new image

Parameters

string $form_field

The name of the form field of the uploaded image.

string $type

The type of image (eg. user, product, etc.)

string $record_id

Optional record ID# of the image to retrieve it later.

integer $is_default

Whether or not this is the default image for this type.

Returns

integer —

The ID# of the image

get()

get(string  $type, string  $record_id = '', string  $size = 'full', boolean  $allow_default = false) 

Retrive image from the database

Parameters

string $type

The type of image (eg. user, product, etc.)

string $record_id

The record ID# of the image.

string $size

The size of the image

boolean $allow_default

If yes and image does not exist, will check for default image

add_thumbnail()

add_thumbnail(string  $image_type, mixed  $record_id, string  $size, integer  $thumb_width, integer  $thumb_height, integer  $is_default) 

Add a thumbnail

Parameters

string $image_type

The type of image (product, profile, etc.)

mixed $record_id

The ID# of the image, unique to the image type.

string $size

The new size of the thumbnail (eg. thumb, small, tiny)

integer $thumb_width

The width of the thumbnail to generate.

integer $thumb_height

The height of the thumbnail to generate.

integer $is_default

A (1/0) defining whether this is the default image for the image type.

display()

display(string  $type, mixed  $record_id = '', string  $size = 'full') 

Display image

Parameters

string $type

The type of image

mixed $record_id

The ID# of the record, unique to the image type.

string $size

The size of the image to display.