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
Afficher le fichier Open project: sjardim/Hugopit Class Usage Examples

Méthodes publiques

Свойство Type Description
$quality Default output image quality

Protected Properties

Свойство Type Description
$filename
$height
$image
$imagestring
$original_info
$width

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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 méthode

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)
Résultat SimpleImage

__destruct() public méthode

Destroy image resource
public __destruct ( )

adaptive_resize() public méthode

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
Résultat SimpleImage

auto_orient() public méthode

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

best_fit() public méthode

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
Résultat SimpleImage

blur() public méthode

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

brightness() public méthode

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

colorize() public méthode

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
Résultat SimpleImage

contrast() public méthode

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

create() public méthode

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
Résultat SimpleImage

crop() public méthode

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
Résultat SimpleImage

desaturate() public méthode

Desaturate (grayscale)
public desaturate ( ) : SimpleImage
Résultat SimpleImage

edges() public méthode

Edge Detect
public edges ( ) : SimpleImage
Résultat SimpleImage

emboss() public méthode

Emboss
public emboss ( ) : SimpleImage
Résultat SimpleImage

file_ext() protected méthode

Returns the file extension of the specified file
protected file_ext ( string $filename ) : string
$filename string
Résultat string

fill() public méthode

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
Résultat SimpleImage

fit_to_height() public méthode

Fit to height (proportionally resize to specified height)
public fit_to_height ( integer $height ) : SimpleImage
$height integer
Résultat SimpleImage

fit_to_width() public méthode

Fit to width (proportionally resize to specified width)
public fit_to_width ( integer $width ) : SimpleImage
$width integer
Résultat SimpleImage

flip() public méthode

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

get_height() public méthode

Get the current height
public get_height ( ) : integer
Résultat integer

get_meta_data() protected méthode

Get meta data of image or base64 string
protected get_meta_data ( ) : SimpleImage
Résultat SimpleImage

get_orientation() public méthode

Get the current orientation
public get_orientation ( ) : string
Résultat string portrait|landscape|square

get_original_info() public méthode

Get info about the original image
public get_original_info ( ) : array
Résultat 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 méthode

Get the current width
public get_width ( ) : integer
Résultat integer

imagecopymerge_alpha() protected méthode

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 méthode

Invert
public invert ( ) : SimpleImage
Résultat SimpleImage

keep_within() protected méthode

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
Résultat integer | float

load() public méthode

Load an image
public load ( string $filename ) : SimpleImage
$filename string Path to image file
Résultat SimpleImage

load_base64() public méthode

Load a base64 string as image
public load_base64 ( $base64string ) : SimpleImage
Résultat SimpleImage

mean_remove() public méthode

Mean Remove
public mean_remove ( ) : SimpleImage
Résultat SimpleImage

normalize_color() protected méthode

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
Résultat array | boolean

opacity() public méthode

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

output() public méthode

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 méthode

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
Résultat string

overlay() public méthode

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
Résultat SimpleImage

pixelate() public méthode

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

resize() public méthode

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

rotate() public méthode

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
Résultat SimpleImage

save() public méthode

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
Résultat SimpleImage

sepia() public méthode

Sepia
public sepia ( ) : SimpleImage
Résultat SimpleImage

sketch() public méthode

Sketch
public sketch ( ) : SimpleImage
Résultat SimpleImage

smooth() public méthode

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

text() public méthode

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
Résultat SimpleImage

thumbnail() public méthode

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
Résultat 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