PHP Класс 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
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$quality Default output image quality

Защищенные свойства (Protected)

Свойство Тип Описание
$filename
$height
$image
$imagestring
$original_info
$width

Открытые методы

Метод Описание
__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

Защищенные методы

Метод Описание
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

Описание методов

__construct() публичный Метод

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)
Результат SimpleImage

__destruct() публичный Метод

Destroy image resource
public __destruct ( )

adaptive_resize() публичный Метод

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
Результат SimpleImage

auto_orient() публичный Метод

Rotates and/or flips an image automatically so the orientation will be correct (based on exif 'Orientation')
public auto_orient ( ) : SimpleImage
Результат SimpleImage

best_fit() публичный Метод

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
Результат SimpleImage

blur() публичный Метод

Blur
public blur ( string $type = 'selective', integer $passes = 1 ) : SimpleImage
$type string selective|gaussian
$passes integer Number of times to apply the filter
Результат SimpleImage

brightness() публичный Метод

Brightness
public brightness ( integer $level ) : SimpleImage
$level integer Darkest = -255, lightest = 255
Результат SimpleImage

colorize() публичный Метод

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
Результат SimpleImage

contrast() публичный Метод

Contrast
public contrast ( integer $level ) : SimpleImage
$level integer Min = -100, max = 100
Результат SimpleImage

create() публичный Метод

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
Результат SimpleImage

crop() публичный Метод

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
Результат SimpleImage

desaturate() публичный Метод

Desaturate (grayscale)
public desaturate ( ) : SimpleImage
Результат SimpleImage

edges() публичный Метод

Edge Detect
public edges ( ) : SimpleImage
Результат SimpleImage

emboss() публичный Метод

Emboss
public emboss ( ) : SimpleImage
Результат SimpleImage

file_ext() защищенный Метод

Returns the file extension of the specified file
protected file_ext ( string $filename ) : string
$filename string
Результат string

fill() публичный Метод

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
Результат SimpleImage

fit_to_height() публичный Метод

Fit to height (proportionally resize to specified height)
public fit_to_height ( integer $height ) : SimpleImage
$height integer
Результат SimpleImage

fit_to_width() публичный Метод

Fit to width (proportionally resize to specified width)
public fit_to_width ( integer $width ) : SimpleImage
$width integer
Результат SimpleImage

flip() публичный Метод

Flip an image horizontally or vertically
public flip ( string $direction ) : SimpleImage
$direction string x|y
Результат SimpleImage

get_height() публичный Метод

Get the current height
public get_height ( ) : integer
Результат integer

get_meta_data() защищенный Метод

Get meta data of image or base64 string
protected get_meta_data ( ) : SimpleImage
Результат SimpleImage

get_orientation() публичный Метод

Get the current orientation
public get_orientation ( ) : string
Результат string portrait|landscape|square

get_original_info() публичный Метод

Get info about the original image
public get_original_info ( ) : array
Результат 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() публичный Метод

Get the current width
public get_width ( ) : integer
Результат integer

imagecopymerge_alpha() защищенный Метод

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() публичный Метод

Invert
public invert ( ) : SimpleImage
Результат SimpleImage

keep_within() защищенный Метод

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
Результат integer | float

load() публичный Метод

Load an image
public load ( string $filename ) : SimpleImage
$filename string Path to image file
Результат SimpleImage

load_base64() публичный Метод

Load a base64 string as image
public load_base64 ( $base64string ) : SimpleImage
Результат SimpleImage

mean_remove() публичный Метод

Mean Remove
public mean_remove ( ) : SimpleImage
Результат SimpleImage

normalize_color() защищенный Метод

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
Результат array | boolean

opacity() публичный Метод

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

output() публичный Метод

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() публичный Метод

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
Результат string

overlay() публичный Метод

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
Результат SimpleImage

pixelate() публичный Метод

Pixelate
public pixelate ( integer $block_size = 10 ) : SimpleImage
$block_size integer Size in pixels of each resulting block
Результат SimpleImage

resize() публичный Метод

Resize an image to the specified dimensions
public resize ( integer $width, integer $height ) : SimpleImage
$width integer
$height integer
Результат SimpleImage

rotate() публичный Метод

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
Результат SimpleImage

save() публичный Метод

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
Результат SimpleImage

sepia() публичный Метод

Sepia
public sepia ( ) : SimpleImage
Результат SimpleImage

sketch() публичный Метод

Sketch
public sketch ( ) : SimpleImage
Результат SimpleImage

smooth() публичный Метод

Smooth
public smooth ( integer $level ) : SimpleImage
$level integer Min = -10, max = 10
Результат SimpleImage

text() публичный Метод

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
Результат SimpleImage

thumbnail() публичный Метод

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
Результат SimpleImage

Описание свойств

$filename защищенное свойство

protected $filename

$height защищенное свойство

protected $height

$image защищенное свойство

protected $image

$imagestring защищенное свойство

protected $imagestring

$original_info защищенное свойство

protected $original_info

$quality публичное свойство

Default output image quality
public $quality

$width защищенное свойство

protected $width