PHP Class SimpleImage

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details: http://www.gnu.org/licenses/gpl.html
Mostrar archivo Open project: sjardim/Hugopit Class Usage Examples

Public Properties

Property Type Description
$quality Default output image quality

Protected Properties

Property Type Description
$filename
$height
$image
$imagestring
$original_info
$width

Public Methods

Method Description
__construct ( null | string $filename = null, integer $width = null, integer | null $height = null, null | string $color = null ) : SimpleImage Create instance and load an image, or create an image from scratch
__destruct ( ) Destroy image resource
adaptive_resize ( integer $width, integer | null $height = null ) : SimpleImage Adaptive resize
auto_orient ( ) : SimpleImage Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation')
best_fit ( integer $max_width, integer $max_height ) : SimpleImage Best fit (proportionally resize to fit in specified width/height)
blur ( string $type = 'selective', integer $passes = 1 ) : SimpleImage Blur
brightness ( integer $level ) : SimpleImage Brightness
colorize ( string $color, float | integer $opacity ) : SimpleImage Colorize
contrast ( integer $level ) : SimpleImage Contrast
create ( integer $width, integer | null $height = null, null | string $color = null ) : SimpleImage Create an image from scratch
crop ( integer $x1, integer $y1, integer $x2, integer $y2 ) : SimpleImage Crop an image
desaturate ( ) : SimpleImage Desaturate (grayscale)
edges ( ) : SimpleImage Edge Detect
emboss ( ) : SimpleImage Emboss
fill ( string $color = '#000000' ) : SimpleImage Fill image with color
fit_to_height ( integer $height ) : SimpleImage Fit to height (proportionally resize to specified height)
fit_to_width ( integer $width ) : SimpleImage Fit to width (proportionally resize to specified width)
flip ( string $direction ) : SimpleImage Flip an image horizontally or vertically
get_height ( ) : integer Get the current height
get_orientation ( ) : string Get the current orientation
get_original_info ( ) : array Get info about the original image
get_width ( ) : integer Get the current width
invert ( ) : SimpleImage Invert
load ( string $filename ) : SimpleImage Load an image
load_base64 ( $base64string ) : SimpleImage Load a base64 string as image
mean_remove ( ) : SimpleImage Mean Remove
opacity ( float | integer $opacity ) Changes the opacity level of the image
output ( null | string $format = null, integer | null $quality = null ) Outputs image without saving
output_base64 ( null | string $format = null, integer | null $quality = null ) : string Outputs image as data base64 to use as img src
overlay ( string $overlay, string $position = 'center', float | integer $opacity = 1, integer $x_offset, integer $y_offset ) : SimpleImage Overlay
pixelate ( integer $block_size = 10 ) : SimpleImage Pixelate
resize ( integer $width, integer $height ) : SimpleImage Resize an image to the specified dimensions
rotate ( integer $angle, string $bg_color = '#000000' ) : SimpleImage Rotate an image
save ( null | string $filename = null, null | integer $quality = null ) : SimpleImage Save an image
sepia ( ) : SimpleImage Sepia
sketch ( ) : SimpleImage Sketch
smooth ( integer $level ) : SimpleImage Smooth
text ( string $text, string $font_file, float | integer $font_size = 12, string $color = '#000000', string $position = 'center', integer $x_offset, integer $y_offset ) : SimpleImage Add text to an image
thumbnail ( integer $width, integer | null $height = null ) : SimpleImage Thumbnail

Protected Methods

Method Description
file_ext ( string $filename ) : string Returns the file extension of the specified file
get_meta_data ( ) : SimpleImage Get meta data of image or base64 string
imagecopymerge_alpha ( $dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct ) Same as PHP's imagecopymerge() function, except preserves alpha-transparency in 24-bit PNGs
keep_within ( integer | float $value, integer | float $min, integer | float $max ) : integer | float Ensures $value is always within $min and $max range.
normalize_color ( string $color ) : array | boolean Converts a hex color value to its RGB equivalent

Method Details

__construct() public method

Create instance and load an image, or create an image from scratch
public __construct ( null | string $filename = null, integer $width = null, integer | null $height = null, null | string $color = null ) : SimpleImage
$filename null | string Path to image file (may be omitted to create image from scratch)
$width integer Image width (is used for creating image from scratch)
$height integer | null If omitted - assumed equal to $width (is used for creating image from scratch)
$color null | string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
(is used for creating image from scratch)
return SimpleImage

__destruct() public method

Destroy image resource
public __destruct ( )

adaptive_resize() public method

This function has been deprecated and will be removed in an upcoming release. Please update your code to use the thumbnail() method instead. The arguments for both methods are exactly the same.
public adaptive_resize ( integer $width, integer | null $height = null ) : SimpleImage
$width integer
$height integer | null If omitted - assumed equal to $width
return SimpleImage

auto_orient() public method

Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation')
public auto_orient ( ) : SimpleImage
return SimpleImage

best_fit() public method

Shrink the image proportionally to fit inside a $width x $height box
public best_fit ( integer $max_width, integer $max_height ) : SimpleImage
$max_width integer
$max_height integer
return SimpleImage

blur() public method

Blur
public blur ( string $type = 'selective', integer $passes = 1 ) : SimpleImage
$type string selective|gaussian
$passes integer Number of times to apply the filter
return SimpleImage

brightness() public method

Brightness
public brightness ( integer $level ) : SimpleImage
$level integer Darkest = -255, lightest = 255
return SimpleImage

colorize() public method

Colorize
public colorize ( string $color, float | integer $opacity ) : SimpleImage
$color string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
$opacity float | integer 0-1
return SimpleImage

contrast() public method

Contrast
public contrast ( integer $level ) : SimpleImage
$level integer Min = -100, max = 100
return SimpleImage

create() public method

Create an image from scratch
public create ( integer $width, integer | null $height = null, null | string $color = null ) : SimpleImage
$width integer Image width
$height integer | null If omitted - assumed equal to $width
$color null | string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
return SimpleImage

crop() public method

Crop an image
public crop ( integer $x1, integer $y1, integer $x2, integer $y2 ) : SimpleImage
$x1 integer Left
$y1 integer Top
$x2 integer Right
$y2 integer Bottom
return SimpleImage

desaturate() public method

Desaturate (grayscale)
public desaturate ( ) : SimpleImage
return SimpleImage

edges() public method

Edge Detect
public edges ( ) : SimpleImage
return SimpleImage

emboss() public method

Emboss
public emboss ( ) : SimpleImage
return SimpleImage

file_ext() protected method

Returns the file extension of the specified file
protected file_ext ( string $filename ) : string
$filename string
return string

fill() public method

Fill image with color
public fill ( string $color = '#000000' ) : SimpleImage
$color string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
return SimpleImage

fit_to_height() public method

Fit to height (proportionally resize to specified height)
public fit_to_height ( integer $height ) : SimpleImage
$height integer
return SimpleImage

fit_to_width() public method

Fit to width (proportionally resize to specified width)
public fit_to_width ( integer $width ) : SimpleImage
$width integer
return SimpleImage

flip() public method

Flip an image horizontally or vertically
public flip ( string $direction ) : SimpleImage
$direction string x|y
return SimpleImage

get_height() public method

Get the current height
public get_height ( ) : integer
return integer

get_meta_data() protected method

Get meta data of image or base64 string
protected get_meta_data ( ) : SimpleImage
return SimpleImage

get_orientation() public method

Get the current orientation
public get_orientation ( ) : string
return string portrait|landscape|square

get_original_info() public method

Get info about the original image
public get_original_info ( ) : array
return array
 array(
	width        => 320,
	height       => 200,
	orientation  => ['portrait', 'landscape', 'square'],
	exif         => array(...),
	mime         => ['image/jpeg', 'image/gif', 'image/png'],
	format       => ['jpeg', 'gif', 'png']
)

get_width() public method

Get the current width
public get_width ( ) : integer
return integer

imagecopymerge_alpha() protected method

Same as PHP's imagecopymerge() function, except preserves alpha-transparency in 24-bit PNGs
protected imagecopymerge_alpha ( $dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct )
$dst_im
$src_im
$dst_x
$dst_y
$src_x
$src_y
$src_w
$src_h
$pct

invert() public method

Invert
public invert ( ) : SimpleImage
return SimpleImage

keep_within() protected method

If lower, $min is returned. If higher, $max is returned.
protected keep_within ( integer | float $value, integer | float $min, integer | float $max ) : integer | float
$value integer | float
$min integer | float
$max integer | float
return integer | float

load() public method

Load an image
public load ( string $filename ) : SimpleImage
$filename string Path to image file
return SimpleImage

load_base64() public method

Load a base64 string as image
public load_base64 ( $base64string ) : SimpleImage
return SimpleImage

mean_remove() public method

Mean Remove
public mean_remove ( ) : SimpleImage
return SimpleImage

normalize_color() protected method

Converts a hex color value to its RGB equivalent
protected normalize_color ( string $color ) : array | boolean
$color string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
return array | boolean

opacity() public method

Changes the opacity level of the image
public opacity ( float | integer $opacity )
$opacity float | integer 0-1

output() public method

Outputs image without saving
public output ( null | string $format = null, integer | null $quality = null )
$format null | string If omitted or null - format of original file will be used, may be gif|jpg|png
$quality integer | null Output image quality in percents 0-100

output_base64() public method

Outputs image as data base64 to use as img src
public output_base64 ( null | string $format = null, integer | null $quality = null ) : string
$format null | string If omitted or null - format of original file will be used, may be gif|jpg|png
$quality integer | null Output image quality in percents 0-100
return string

overlay() public method

Overlay an image on top of another, works with 24-bit PNG alpha-transparency
public overlay ( string $overlay, string $position = 'center', float | integer $opacity = 1, integer $x_offset, integer $y_offset ) : SimpleImage
$overlay string An image filename or a SimpleImage object
$position string center|top|left|bottom|right|top left|top right|bottom left|bottom right
$opacity float | integer Overlay opacity 0-1
$x_offset integer Horizontal offset in pixels
$y_offset integer Vertical offset in pixels
return SimpleImage

pixelate() public method

Pixelate
public pixelate ( integer $block_size = 10 ) : SimpleImage
$block_size integer Size in pixels of each resulting block
return SimpleImage

resize() public method

Resize an image to the specified dimensions
public resize ( integer $width, integer $height ) : SimpleImage
$width integer
$height integer
return SimpleImage

rotate() public method

Rotate an image
public rotate ( integer $angle, string $bg_color = '#000000' ) : SimpleImage
$angle integer 0-360
$bg_color string Hex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
return SimpleImage

save() public method

The resulting format will be determined by the file extension.
public save ( null | string $filename = null, null | integer $quality = null ) : SimpleImage
$filename null | string If omitted - original file will be overwritten
$quality null | integer Output image quality in percents 0-100
return SimpleImage

sepia() public method

Sepia
public sepia ( ) : SimpleImage
return SimpleImage

sketch() public method

Sketch
public sketch ( ) : SimpleImage
return SimpleImage

smooth() public method

Smooth
public smooth ( integer $level ) : SimpleImage
$level integer Min = -10, max = 10
return SimpleImage

text() public method

Add text to an image
public text ( string $text, string $font_file, float | integer $font_size = 12, string $color = '#000000', string $position = 'center', integer $x_offset, integer $y_offset ) : SimpleImage
$text string
$font_file string
$font_size float | integer
$color string
$position string
$x_offset integer
$y_offset integer
return SimpleImage

thumbnail() public method

This function attempts to get the image to as close to the provided dimensions as possible, and then crops the remaining overflow (from the center) to get the image to be the size specified. Useful for generating thumbnails.
public thumbnail ( integer $width, integer | null $height = null ) : SimpleImage
$width integer
$height integer | null If omitted - assumed equal to $width
return SimpleImage

Property Details

$filename protected_oe property

protected $filename

$height protected_oe property

protected $height

$image protected_oe property

protected $image

$imagestring protected_oe property

protected $imagestring

$original_info protected_oe property

protected $original_info

$quality public_oe property

Default output image quality
public $quality

$width protected_oe property

protected $width