AnewtImage Class Reference

Generic image class. More...

List of all members.

Public Member Functions

 __construct ($width, $height, $img=null)
 Create a new image instance.
 destroy ()
 Destroy this image and all allocated resources.
 get_dimensions ()
 Return dimensions of this image.
 set_dimensions ($width, $height)
 Set the image dimension to the specified width and height.
 crop ($x, $y, $width, $height)
 Crop the image to the specified dimensions.
 get_width ()
 Get the width of the current image.
 set_width ($new_width)
 Set the width of the current image.
 get_height ()
 Get the height of the current image.
 set_height ($new_height)
 Set the height of the current image.
 resize ($width, $height, $resample=null)
 Resize image to the specified width and height.
 resize_relative ($scale_factor, $resample=null)
 Resize image relative to its current size.
 resize_percentage ($scale_percentage, $resample=null)
 Resize image relative to its current size by providing a percentage.
 resize_width ($width, $resample=null)
 Resize image to the specified width.
 resize_height ($height, $resample=null)
 Resize image to the specified height.
 resize_within ($width, $height, $scale_up=null, $resample=null)
 Resize image so that it fits the specified dimensions.
 color_from_string ($str)
 Parses a color from a string.
 color_from_rgb ($red, $green, $blue)
 Allocates as color based on red, green and blue values.
 color_from_rgba ($red, $green, $blue, $alpha)
 Allocates as color based on red, green, blue and alpha values.
 fill ($color)
 Fills the complete image with the specified color.
 create_drawing_context ()
 Create a new drawing context for this image.
 save ()
 Save a previously loaded image back to disk.
 flush ()
 Flush the output to the browser.
 flush_png ()
 Flush this image as a PNG image.
 save_png ($filename)
 Save this image as a PNG image.
 flush_jpeg ($quality=null)
 Flush this image as a JPEG image.
 save_jpeg ($filename, $quality=null)
 Save this image as a JPEG image.

Static Public Member Functions

static from_file ($filename)
 Load an image from a file.
static from_png ($filename)
 Load a PNG image from a file.
static from_jpeg ($filename)
 Load a JPEG image from a file.
static from_gif ($filename)
 Load a GIF image from a file.
static from_string ($str)
 Load an image from a string.
static color_to_string ($color)
 Convert a color to hexadecimal representation suitable for usage in HTML and CSS.
static color_to_rgb ($color)
 Convert a color to a (red, green, blue) tuple.

Public Attributes

 $__img = null
 Image instance.

Protected Member Functions

 get_quality_ ()
 Default image quality.
 pre_output ()
 Callback prior to image output.
 post_output ()
 Callback after image output.

Private Member Functions

 _allocate_color ($red, $green, $blue, $alpha=null)
 Allocates a color in the current image.
 _content_type ($content_type)
 Send a Content-type header.

Static Private Member Functions

static _filename_looks_like_png ($filename)
 Check if filename looks like a PNG filename.
static _filename_looks_like_jpeg ($filename)
 Check if filename looks like a JPEG filename.

Private Attributes

 $__allocated_colors = array()
 List of allocated colors.


Detailed Description

Generic image class.

This class supports loading (PNG, JPEG, GIF) and saving of (PNG, JPEG) images. This class heavily uses the image functions from the GD2 library bundled with PHP, but provides a decent API and many convenience methods for loading, saving, resampling, resizing and drawing.

Definition at line 17 of file image.lib.php.


Constructor & Destructor Documentation

AnewtImage::__construct ( width,
height,
img = null 
)

Create a new image instance.

This method seems to accept three parameters, but you should really only provide the width and height. The third parameter is for internal usage only!

Parameters:
$width The width of the image (in pixels)
$height The height of the image (in pixels)
$img Internal parameter for private internal use. Do not provide this.

Definition at line 176 of file image.lib.php.


Member Function Documentation

static AnewtImage::from_file ( filename  )  [static]

Load an image from a file.

This method tries to detect the filetype automatically and will abort if the automatic detection failed.

Parameters:
$filename Filename of the image to load.
Returns:
A new AnewtImage instance

Definition at line 31 of file image.lib.php.

static AnewtImage::from_png ( filename  )  [static]

Load a PNG image from a file.

Parameters:
$filename Filename of the image to load.
Returns:
A new AnewtImage instance

Definition at line 55 of file image.lib.php.

static AnewtImage::from_jpeg ( filename  )  [static]

Load a JPEG image from a file.

Parameters:
$filename Filename of the image to load.
Returns:
A new AnewtImage instance

Definition at line 72 of file image.lib.php.

static AnewtImage::from_gif ( filename  )  [static]

Load a GIF image from a file.

Parameters:
$filename Filename of the image to load.
Returns:
A new AnewtImage instance

Definition at line 89 of file image.lib.php.

static AnewtImage::from_string ( str  )  [static]

Load an image from a string.

The image type is automatically detected.

Parameters:
$str The str holding the image data.
Returns:
A new AnewtImage instance

Definition at line 106 of file image.lib.php.

static AnewtImage::_filename_looks_like_png ( filename  )  [static, private]

Check if filename looks like a PNG filename.

Parameters:
$filename Filename to test.
Returns:
True if the filename looks like a PNG filename, false otherwise.

Definition at line 122 of file image.lib.php.

static AnewtImage::_filename_looks_like_jpeg ( filename  )  [static, private]

Check if filename looks like a JPEG filename.

Parameters:
$filename Filename to test.
Returns:
True if the filename looks like a JPEG filename, false otherwise.

Definition at line 137 of file image.lib.php.

AnewtImage::destroy (  ) 

Destroy this image and all allocated resources.

Do not invoke any instance methods after this function has been called.

Definition at line 202 of file image.lib.php.

AnewtImage::get_quality_ (  )  [protected]

Default image quality.

This is mainly used for JPEG images and returns the value 85.

Returns:
The number 85.

Definition at line 218 of file image.lib.php.

AnewtImage::get_dimensions (  ) 

Return dimensions of this image.

Returns:
Array with (width, height) integer values.

Definition at line 232 of file image.lib.php.

AnewtImage::set_dimensions ( width,
height 
)

Set the image dimension to the specified width and height.

Note that this crops the image from the top left corner.

Parameters:
$width The width of the image (in pixels)
$height The height of the image (in pixels)
See also:
AnewtImage::crop

Definition at line 248 of file image.lib.php.

AnewtImage::crop ( x,
y,
width,
height 
)

Crop the image to the specified dimensions.

Parameters:
$x The x coordinate of the rectangle to crop to (in pixels)
$y The y coordinate of the rectangle to crop to (in pixels)
$width The width of the rectangle to crop to (in pixels)
$height The height of the rectangle to crop to (in pixels)
See also:
AnewtImage::set_dimensions

Definition at line 267 of file image.lib.php.

AnewtImage::get_width (  ) 

Get the width of the current image.

Returns:
Width of the image

Definition at line 286 of file image.lib.php.

AnewtImage::set_width ( new_width  ) 

Set the width of the current image.

This crops the image if the new size is smaller than the current value.

Parameters:
$new_width New width of the image.

Definition at line 298 of file image.lib.php.

AnewtImage::get_height (  ) 

Get the height of the current image.

Returns:
Height of the image

Definition at line 309 of file image.lib.php.

AnewtImage::set_height ( new_height  ) 

Set the height of the current image.

This crops the image if the new size is smaller than the current value.

Parameters:
$new_height New height of the image.

Definition at line 321 of file image.lib.php.

AnewtImage::resize ( width,
height,
resample = null 
)

Resize image to the specified width and height.

Parameters:
$width The new width
$height The new height
$resample Whether to use image resampling (default is true)

Definition at line 338 of file image.lib.php.

AnewtImage::resize_relative ( scale_factor,
resample = null 
)

Resize image relative to its current size.

Parameters:
$scale_factor Scale factor. Values less than 0 shrink the image, values above 1 enlarge the image.
$resample Whether to use image resampling (default is true)

Definition at line 385 of file image.lib.php.

AnewtImage::resize_percentage ( scale_percentage,
resample = null 
)

Resize image relative to its current size by providing a percentage.

Parameters:
$scale_percentage Scale factor as percentage. Values less than 100 shrink the image, values above 100 enlarge the image.
$resample Whether to use image resampling (default is true)

Definition at line 407 of file image.lib.php.

AnewtImage::resize_width ( width,
resample = null 
)

Resize image to the specified width.

The height is adjusted automatically, keeping the same aspect ratio.

Parameters:
$width The new width
$resample Whether to use image resampling (default is true)

Definition at line 423 of file image.lib.php.

AnewtImage::resize_height ( height,
resample = null 
)

Resize image to the specified height.

The width is adjusted automatically, keeping the same aspect ratio.

Parameters:
$height The new height
$resample Whether to use image resampling (default is true)

Definition at line 440 of file image.lib.php.

AnewtImage::resize_within ( width,
height,
scale_up = null,
resample = null 
)

Resize image so that it fits the specified dimensions.

Aspect ratio is preserved.

Parameters:
$width The maximum width to fit in.
$height The maximum height to fit in.
$scale_up Whether to scale up if both existing dimensions are smaller than the specified dimensions (default is false).
$resample Whether to use image resampling (default is true)

Definition at line 464 of file image.lib.php.

AnewtImage::_allocate_color ( red,
green,
blue,
alpha = null 
) [private]

Allocates a color in the current image.

Parameters:
$red Red component value
$green Green component value
$blue Blue component value
$alpha Alpha component value
Returns:
Allocated color value

Definition at line 494 of file image.lib.php.

AnewtImage::color_from_string ( str  ) 

Parses a color from a string.

Hexadecimal values (HTML/CSS format) are converted to a color value, e.g. #ff0000 for red. The alpha channel (transparency) can be provided as well by adding two more letters, e.g. #ff000012. Values consisting of only 3 letters are accepted as well and interpreted according to the same semantics as HTML/CSS uses.

The leading # character is optional.

Parameters:
$str The string to parse.
Returns:
Allocated color value
See also:
AnewtImage::color_from_rgb

AnewtImage::color_from_rgba

Definition at line 542 of file image.lib.php.

AnewtImage::color_from_rgb ( red,
green,
blue 
)

Allocates as color based on red, green and blue values.

All values should be between 0 and 255.

Parameters:
$red Red component value
$green Green component value
$blue Blue component value
Returns:
Allocated color value
See also:
AnewtImage::color_from_string

AnewtImage::color_from_rgba

Definition at line 582 of file image.lib.php.

AnewtImage::color_from_rgba ( red,
green,
blue,
alpha 
)

Allocates as color based on red, green, blue and alpha values.

All values should be between 0 and 255.

Parameters:
$red Red component value
$green Green component value
$blue Blue component value
$alpha Alpha component value
Returns:
Allocated color value
See also:
AnewtImage::color_from_string

AnewtImage::color_from_rgb

Definition at line 602 of file image.lib.php.

static AnewtImage::color_to_string ( color  )  [static]

Convert a color to hexadecimal representation suitable for usage in HTML and CSS.

The resulting string includes a leading # character.

Parameters:
$color The color to convert
Returns:
String representation of the color

Definition at line 619 of file image.lib.php.

static AnewtImage::color_to_rgb ( color  )  [static]

Convert a color to a (red, green, blue) tuple.

Parameters:
$color The color to convert
Returns:
Array with three integer values for the red, green and blue component.

Definition at line 635 of file image.lib.php.

AnewtImage::fill ( color  ) 

Fills the complete image with the specified color.

This sets the background of the image if called early, and overwrites the current image contents if called after any loading or drawing operations. Note that, when using a color with alpha blending, the current contents of the image are effectively colorized with the specified color.

Parameters:
$color The color to use. This color may include an alpha component.

Definition at line 661 of file image.lib.php.

AnewtImage::create_drawing_context (  ) 

Create a new drawing context for this image.

You should set some properties and call drawing methods on the returned object instance to create dynamic images.

Returns:
A new AnewtImageDrawingContext instance.

Definition at line 678 of file image.lib.php.

AnewtImage::save (  ) 

Save a previously loaded image back to disk.

See also:
AnewtImage::save_png

AnewtImage::save_jpeg

AnewtImage::flush

Definition at line 697 of file image.lib.php.

AnewtImage::flush (  ) 

Flush the output to the browser.

The 'filename' property is inspected to see what file type to use, e.g. PNG or JPEG.

See also:
AnewtImage::flush_png

AnewtImage::flush_jpeg

AnewtImage::save

Definition at line 718 of file image.lib.php.

AnewtImage::_content_type ( content_type  )  [private]

Send a Content-type header.

Parameters:
$content_type The content-type to send.

Definition at line 737 of file image.lib.php.

AnewtImage::flush_png (  ) 

Flush this image as a PNG image.

See also:
AnewtImage::flush

AnewtImage::save_png

Definition at line 749 of file image.lib.php.

AnewtImage::save_png ( filename  ) 

Save this image as a PNG image.

Parameters:
$filename The filename to save to.
See also:
AnewtImage::save

AnewtImage::flush_png

Definition at line 766 of file image.lib.php.

AnewtImage::flush_jpeg ( quality = null  ) 

Flush this image as a JPEG image.

Parameters:
$quality The JPEG quality to use for saving (optional).
See also:
AnewtImage::flush

AnewtImage::save_jpeg

Definition at line 784 of file image.lib.php.

AnewtImage::save_jpeg ( filename,
quality = null 
)

Save this image as a JPEG image.

Parameters:
$filename The filename to save to.
$quality The JPEG quality to use for saving (optional). This does not affect the image contents itself; that happens only after opening the file from disk after writing.
See also:
AnewtImage::save

AnewtImage::flush_jpeg

Definition at line 811 of file image.lib.php.

AnewtImage::pre_output (  )  [protected]

Callback prior to image output.

Override this method if you want to change the image before it is output, e.g. draw an overlay or even draw a sparkline...

Reimplemented in AnewtSparklineImageBar, and AnewtSparklineImageLine.

Definition at line 833 of file image.lib.php.

AnewtImage::post_output (  )  [protected]

Callback after image output.

Override this method if you want to do postprocessing, e.g. some cleaning up routines could go here. Note that this will not have any effect on the image; it is already saved to a file or sent to the browser.

Definition at line 841 of file image.lib.php.


Member Data Documentation

AnewtImage::$__img = null

Image instance.

Though not marked as such, this is a private variable that should only be accessed from within this module.

Definition at line 154 of file image.lib.php.


The documentation for this class was generated from the following file:

Generated on Sun Aug 2 22:54:37 2009 for Anewt by  doxygen 1.5.9