Constants

memory_value

memory_value

Properties

$image_src

$image_src

Stores the image source given for reference

$is_remote

$is_remote

If the file is remote or not

$options

$options

Allow the user to set the options for the setup

$cached_image_directory

$cached_image_directory

The location of the cached images directory

$cached_filename

$cached_filename

The name of the cached file

$gd_version

$gd_version

Stores the server's version of the GD Library, if enabled

$memory_limit

$memory_limit

The memory limit currently established on the server

$file_mime_type

$file_mime_type

The file mime type

$file_extension

$file_extension

The extension of the file

$local_image_src

$local_image_src

The original size of the file

$src_filesize

$src_filesize

The original size of the file

$cached_filesize

$cached_filesize

The extension of the file

Methods

__construct()

__construct(array $options) : object

Constructor function

Parameters

array $options

Options include the keys 'echo' (boolean) and 'cache_time' (integer). 'cache_time' is currently not employed, but in place for future reference.

Returns

object —

Returns the class object for the user to reference it in the future.

can_run_image_cache()

can_run_image_cache() : bool

Validates whether the user can use this class or not, based on the GD Version their server is carrying.

Returns

bool

cache()

cache( $image) : string

Caches the image. When using this method, the image will be compressed and then cached.

Parameters

$image

Returns

string —

The source file to be referenced after compressing an image

download_image()

download_image()

Downloads a remote file and stores it locally to be used for compression

make_cache_directory()

make_cache_directory() : bool

Creates the cached directory

Returns

bool —

If the directory was successfully created or not

fetch_image()

fetch_image() : \If

Fetch the image as a resource and save it into the cache directory.

Returns

\If —

the image was successfully created or not

docroot_to_url()

docroot_to_url( $src) : string

Returns

Parameters

$src

Returns

string —

The URL of the image

pre_set_class_vars()

pre_set_class_vars()

Sets up all class variables in one central function.

link_is_broken()

link_is_broken(string $url) : bool

Utility function to determine of the link in question is broken or not.

Parameters

string $url

The url to check validate

Returns

bool —

Indicates whether or not the link is broken

is_image_local()

is_image_local() : bool

Quick and dirty way to see if the file is remote or local. Deeper checking comes later if we don't find a compressed version of the file locally.

Returns

bool —

Whether or not the image is remote

set_is_remote()

set_is_remote()

Determines if the image is local or being referenced from a remote URL

set_cached_filename()

set_cached_filename()

This function creates the filename of the new image using an MD5 hash of the original filename. This helps to create a unique filename for the newly compressed image so that this class can easily find and determine if the image has already been compressed and stored locally.

Employing use of the "alt" and "title" tags on the image (which hopefully you're already doing) will negate any potentially negative impacts on SEO. See this article for more information: http://searchenginewatch.com/article/2120682/Image-Optimization-How-to-Rank-on-Image-Search

cached_file_exists()

cached_file_exists()

Simply determines if a compressed of the image that's sent is already compressed or not.

set_file_mime_type()

set_file_mime_type()

Stores the file's mime type and validates that the file being compressed is indeed an image.

set_memory_limit()

set_memory_limit()

Stores the original value of the server's memory limit

increase_memory_limit()

increase_memory_limit()

Temporarily increases the servers memory limit to 2480 MB to handle building larger images. Based on initial tests, this seems to be a large enough increase to handle rebuilding jpg images as large as 4300px wide with no pre-compression.

reset_memory_limit()

reset_memory_limit()

Resets the servers memory limit to its original value

error()

error(String $status)

Displays an error and kills the script

Parameters

String $status

The message to be passed to the native exit() function