OpenSencillo  2016.106
Long live the simplicity of PHP
 All Data Structures Namespaces Files Functions Pages
SimpleImage Class Reference

Public Member Functions

 __construct ($filename=null, $width=null, $height=null, $color=null)
 
 __destruct ()
 
 adaptive_resize ($width, $height=null)
 
 auto_orient ()
 
 best_fit ($max_width, $max_height)
 
 blur ($type= 'selective', $passes=1)
 
 brightness ($level)
 
 contrast ($level)
 
 colorize ($color, $opacity)
 
 create ($width, $height=null, $color=null)
 
 crop ($x1, $y1, $x2, $y2)
 
 desaturate ()
 
 edges ()
 
 emboss ()
 
 fill ($color= '#000000')
 
 fit_to_height ($height)
 
 fit_to_width ($width)
 
 flip ($direction)
 
 get_height ()
 
 get_orientation ()
 
 get_original_info ()
 
 get_width ()
 
 invert ()
 
 load ($filename)
 
 load_base64 ($base64string)
 
 mean_remove ()
 
 opacity ($opacity)
 
 output ($format=null, $quality=null)
 
 output_base64 ($format=null, $quality=null)
 
 overlay ($overlay, $position= 'center', $opacity=1, $x_offset=0, $y_offset=0)
 
 pixelate ($block_size=10)
 
 resize ($width, $height)
 
 rotate ($angle, $bg_color= '#000000')
 
 save ($filename=null, $quality=null)
 
 sepia ()
 
 sketch ()
 
 smooth ($level)
 
 text ($text, $font_file, $font_size=12, $color= '#000000', $position= 'center', $x_offset=0, $y_offset=0)
 
 thumbnail ($width, $height=null)
 

Data Fields

 $quality = 80
 
 $filename
 
 $original_info
 
 $width
 
 $height
 
 $imagestring
 

Protected Member Functions

 file_ext ($filename)
 
 get_meta_data ()
 
 imagecopymerge_alpha ($dst_im, $src_im, $dst_x, $dst_y, $src_x, $src_y, $src_w, $src_h, $pct)
 
 keep_within ($value, $min, $max)
 
 normalize_color ($color)
 

Protected Attributes

 $image
 

Detailed Description

Definition at line 21 of file simple.image.simp.php.

Constructor & Destructor Documentation

__construct (   $filename = null,
  $width = null,
  $height = null,
  $color = null 
)

Create instance and load an image, or create an image from scratch

Parameters
null | string$filenamePath to image file (may be omitted to create image from scratch)
int$widthImage width (is used for creating image from scratch)
int | null$heightIf omitted - assumed equal to $width (is used for creating image from scratch)
null | string$colorHex 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)
Returns
SimpleImage
Exceptions
Exception

Definition at line 45 of file simple.image.simp.php.

__destruct ( )

Destroy image resource

Definition at line 58 of file simple.image.simp.php.

Member Function Documentation

adaptive_resize (   $width,
  $height = null 
)

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.

Parameters
int$width
int | null$heightIf omitted - assumed equal to $width
Returns
SimpleImage

Definition at line 77 of file simple.image.simp.php.

auto_orient ( )

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

Returns
SimpleImage

Definition at line 89 of file simple.image.simp.php.

best_fit (   $max_width,
  $max_height 
)

Best fit (proportionally resize to fit in specified width/height)

Shrink the image proportionally to fit inside a $width x $height box

Parameters
int$max_width
int$max_height
Returns
SimpleImage

Definition at line 142 of file simple.image.simp.php.

blur (   $type = 'selective',
  $passes = 1 
)

Blur

Parameters
string$typeselective|gaussian
int$passesNumber of times to apply the filter
Returns
SimpleImage

Definition at line 180 of file simple.image.simp.php.

brightness (   $level)

Brightness

Parameters
int$levelDarkest = -255, lightest = 255
Returns
SimpleImage

Definition at line 203 of file simple.image.simp.php.

colorize (   $color,
  $opacity 
)

Colorize

Parameters
string$colorHex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
float | int$opacity0-1
Returns
SimpleImage

Definition at line 232 of file simple.image.simp.php.

contrast (   $level)

Contrast

Parameters
int$levelMin = -100, max = 100
Returns
SimpleImage

Definition at line 217 of file simple.image.simp.php.

create (   $width,
  $height = null,
  $color = null 
)

Create an image from scratch

Parameters
int$widthImage width
int | null$heightIf omitted - assumed equal to $width
null | string$colorHex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
Returns
SimpleImage

Definition at line 250 of file simple.image.simp.php.

crop (   $x1,
  $y1,
  $x2,
  $y2 
)

Crop an image

Parameters
int$x1Left
int$y1Top
int$x2Right
int$y2Bottom
Returns
SimpleImage

Definition at line 284 of file simple.image.simp.php.

desaturate ( )

Desaturate (grayscale)

Returns
SimpleImage

Definition at line 317 of file simple.image.simp.php.

edges ( )

Edge Detect

Returns
SimpleImage

Definition at line 328 of file simple.image.simp.php.

emboss ( )

Emboss

Returns
SimpleImage

Definition at line 339 of file simple.image.simp.php.

file_ext (   $filename)
protected

Returns the file extension of the specified file

Parameters
string$filename
Returns
string

Definition at line 1050 of file simple.image.simp.php.

fill (   $color = '#000000')

Fill image with color

Parameters
string$colorHex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
Returns
SimpleImage

Definition at line 353 of file simple.image.simp.php.

fit_to_height (   $height)

Fit to height (proportionally resize to specified height)

Parameters
int$height
Returns
SimpleImage

Definition at line 373 of file simple.image.simp.php.

fit_to_width (   $width)

Fit to width (proportionally resize to specified width)

Parameters
int$width
Returns
SimpleImage

Definition at line 390 of file simple.image.simp.php.

flip (   $direction)

Flip an image horizontally or vertically

Parameters
string$directionx|y
Returns
SimpleImage

Definition at line 407 of file simple.image.simp.php.

get_height ( )

Get the current height

Returns
int

Definition at line 438 of file simple.image.simp.php.

get_meta_data ( )
protected

Get meta data of image or base64 string

Parameters
string | null$imagestringIf omitted treat as a normal image
Returns
SimpleImage
Exceptions
Exception

Definition at line 1069 of file simple.image.simp.php.

get_orientation ( )

Get the current orientation

Returns
string portrait|landscape|square

Definition at line 448 of file simple.image.simp.php.

get_original_info ( )

Get info about the original image

Returns
array
 array(
    width        => 320,
    height       => 200,
    orientation  => ['portrait', 'landscape', 'square'],
    exif         => array(...),
    mime         => ['image/jpeg', 'image/gif', 'image/png'],
    format       => ['jpeg', 'gif', 'png']
)

Definition at line 475 of file simple.image.simp.php.

get_width ( )

Get the current width

Returns
int

Definition at line 485 of file simple.image.simp.php.

imagecopymerge_alpha (   $dst_im,
  $src_im,
  $dst_x,
  $dst_y,
  $src_x,
  $src_y,
  $src_w,
  $src_h,
  $pct 
)
protected

Same as PHP's imagecopymerge() function, except preserves alpha-transparency in 24-bit PNGs

Parameters
$dst_im
$src_im
$dst_x
$dst_y
$src_x
$src_y
$src_w
$src_h
$pcthttp://www.php.net/manual/en/function.imagecopymerge.php#88456

Definition at line 1128 of file simple.image.simp.php.

invert ( )

Invert

Returns
SimpleImage

Definition at line 495 of file simple.image.simp.php.

keep_within (   $value,
  $min,
  $max 
)
protected

Ensures $value is always within $min and $max range.

If lower, $min is returned. If higher, $max is returned.

Parameters
int | float$value
int | float$min
int | float$max
Returns
int|float

Definition at line 1191 of file simple.image.simp.php.

load (   $filename)

Load an image

Parameters
string$filenamePath to image file
Returns
SimpleImage
Exceptions
Exception

Definition at line 509 of file simple.image.simp.php.

load_base64 (   $base64string)

Load a base64 string as image

Parameters
string$filenamebase64 string
Returns
SimpleImage

Definition at line 527 of file simple.image.simp.php.

mean_remove ( )

Mean Remove

Returns
SimpleImage

Definition at line 543 of file simple.image.simp.php.

normalize_color (   $color)
protected

Converts a hex color value to its RGB equivalent

Parameters
string$colorHex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
Returns
array|bool

Definition at line 1214 of file simple.image.simp.php.

opacity (   $opacity)

Changes the opacity level of the image

Parameters
float | int$opacity0-1
Exceptions
Exception

Definition at line 556 of file simple.image.simp.php.

output (   $format = null,
  $quality = null 
)

Outputs image without saving

Parameters
null | string$formatIf omitted or null - format of original file will be used, may be gif|jpg|png
int | null$qualityOutput image quality in percents 0-100
Exceptions
Exception

Definition at line 587 of file simple.image.simp.php.

output_base64 (   $format = null,
  $quality = null 
)

Outputs image as data base64 to use as img src

Parameters
null | string$formatIf omitted or null - format of original file will be used, may be gif|jpg|png
int | null$qualityOutput image quality in percents 0-100
Returns
string
Exceptions
Exception

Definition at line 644 of file simple.image.simp.php.

overlay (   $overlay,
  $position = 'center',
  $opacity = 1,
  $x_offset = 0,
  $y_offset = 0 
)

Overlay

Overlay an image on top of another, works with 24-bit PNG alpha-transparency

Parameters
string$overlayAn image filename or a SimpleImage object
string$positioncenter|top|left|bottom|right|top left|top right|bottom left|bottom right
float | int$opacityOverlay opacity 0-1
int$x_offsetHorizontal offset in pixels
int$y_offsetVertical offset in pixels
Returns
SimpleImage

Definition at line 707 of file simple.image.simp.php.

pixelate (   $block_size = 10)

Pixelate

Parameters
int$block_sizeSize in pixels of each resulting block
Returns
SimpleImage

Definition at line 773 of file simple.image.simp.php.

resize (   $width,
  $height 
)

Resize an image to the specified dimensions

Parameters
int$width
int$height
Returns
SimpleImage

Definition at line 787 of file simple.image.simp.php.

rotate (   $angle,
  $bg_color = '#000000' 
)

Rotate an image

Parameters
int$angle0-360
string$bg_colorHex color string, array(red, green, blue) or array(red, green, blue, alpha). Where red, green, blue - integers 0-255, alpha - integer 0-127
Returns
SimpleImage

Definition at line 829 of file simple.image.simp.php.

save (   $filename = null,
  $quality = null 
)

Save an image

The resulting format will be determined by the file extension.

Parameters
null | string$filenameIf omitted - original file will be overwritten
null | int$qualityOutput image quality in percents 0-100
Returns
SimpleImage
Exceptions
Exception

Definition at line 859 of file simple.image.simp.php.

sepia ( )

Sepia

Returns
SimpleImage

Definition at line 897 of file simple.image.simp.php.

sketch ( )

Sketch

Returns
SimpleImage

Definition at line 909 of file simple.image.simp.php.

smooth (   $level)

Smooth

Parameters
int$levelMin = -10, max = 10
Returns
SimpleImage

Definition at line 922 of file simple.image.simp.php.

text (   $text,
  $font_file,
  $font_size = 12,
  $color = '#000000',
  $position = 'center',
  $x_offset = 0,
  $y_offset = 0 
)

Add text to an image

Parameters
string$text
string$font_file
float | int$font_size
string$color
string$position
int$x_offset
int$y_offset
Returns
SimpleImage
Exceptions
Exception

Definition at line 942 of file simple.image.simp.php.

thumbnail (   $width,
  $height = null 
)

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.

Parameters
int$width
int | null$heightIf omitted - assumed equal to $width
Returns
SimpleImage

Definition at line 1019 of file simple.image.simp.php.


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