Watimage API
  • Namespace
  • Class

Namespaces

  • Elboletaire
    • Watimage
      • Exception

Classes

  • Image
  • Normalize
  • Watermark
  • Watimage

Class Image

The Image class. The main code of Watimage.

Direct known subclasses

Elboletaire\Watimage\Watermark

Namespace: Elboletaire\Watimage
Copyright: 2015 Òscar Casajuana
License: MIT
Author: Òscar Casajuana
Link: https://github.com/elboletaire/Watimage
Located at Image.php

Methods summary

public
# __construct( string $file = null, $autoOrientate = true )

Constructor method. You can pass a filename to be loaded by default or load it later with load('filename.ext')

Constructor method. You can pass a filename to be loaded by default or load it later with load('filename.ext')

Parameters

$file
Filepath of the image to be loaded.
$autoOrientate
public
# __destruct( )

Ensure everything gets emptied on object destruction.

Ensure everything gets emptied on object destruction.

Codecoverageignore

public resource
# createResourceImage( string $filename, string $mime )

Creates a resource image.

Creates a resource image.

This method was using imagecreatefromstring but I decided to switch after reading this: https://thenewphalls.wordpress.com/2012/12/27/imagecreatefromstring-vs-imagecreatefromformat

Parameters

$filename
Image file path/name.
$mime

Image mime or string if creating from string (no base64 encoded).

Returns

resource

Throws

Elboletaire\Watimage\Exception\InvalidMimeException
public Elboletaire\Watimage\Image
# destroy( )

Cleans up everything to start again.

Cleans up everything to start again.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# generate( string $filename = null, string $output = null, boolean $header = true )

Outputs or saves the image.

Outputs or saves the image.

Parameters

$filename
Filename to be saved. Empty to directly print on screen.
$output
Use it to overwrite the output format when no $filename is passed.
$header
Wheather or not generate the output header.

Returns

Elboletaire\Watimage\Image

Throws

Elboletaire\Watimage\Exception\InvalidArgumentException
If output format is not recognised.
public boolean
# save( string $filename = null )

Similar to generate, except that passing an empty $filename here will overwrite the original file.

Similar to generate, except that passing an empty $filename here will overwrite the original file.

Parameters

$filename
Filename to be saved. Empty to overwrite original file.

Returns

boolean
public string
# toString( boolean $prefix = false )

Returns the base64 version for the current Image.

Returns the base64 version for the current Image.

Parameters

$prefix

Whether or not prefix the string with data:{mime};base64,.

Returns

string
public Elboletaire\Watimage\Watimage
# load( mixed $filename )

Loads image and (optionally) its options.

Loads image and (optionally) its options.

Parameters

$filename
Filename string or array containing both filename and quality

Returns

Elboletaire\Watimage\Watimage

Throws

Elboletaire\Watimage\Exception\FileNotExistException
Elboletaire\Watimage\Exception\InvalidArgumentException
public Elboletaire\Watimage\Image
# fromString( string $string )

Loads an image from string. Can be either base64 encoded or not.

Loads an image from string. Can be either base64 encoded or not.

Parameters

$string
The image string to be loaded.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# autoOrientate( )

Auto-orients an image based on its exif Orientation information.

Auto-orients an image based on its exif Orientation information.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# rotate( integer $degrees, mixed $bgcolor = Elboletaire\Watimage\Image::COLOR_TRANSPARENT )

Rotates an image.

Rotates an image.

Will rotate clockwise when using positive degrees.

Parameters

$degrees
Rotation angle in degrees.
$bgcolor
Background to be used for the background, transparent by default.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# resize( string $type, mixed $width, integer $height = null )

All in one method for all resize methods.

All in one method for all resize methods.

Parameters

$type
Type of resize: resize, resizemin, reduce, crop & resizecrop.
$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# classicResize( mixed $width, integer $height = null )

Resizes maintaining aspect ratio.

Resizes maintaining aspect ratio.

Maintains the aspect ratio of the image and makes sure that it fits within the max width and max height (thus some side will be smaller).

Parameters

$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# resizeMin( mixed $width, integer $height = null )

Backwards compatibility alias for reduce (which has the same logic).

Backwards compatibility alias for reduce (which has the same logic).

Deprecated

Parameters

$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image

Codecoverageignore

public Elboletaire\Watimage\Image
# classicCrop( mixed $width, integer $height = null )

A straight centered crop.

A straight centered crop.

Parameters

$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# resizeCrop( mixed $width, integer $height = null )

Resizes to max, then crops to center.

Resizes to max, then crops to center.

Parameters

$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# reduce( mixed $width, integer $height = null )

Resizes maintaining aspect ratio but not exceeding width / height.

Resizes maintaining aspect ratio but not exceeding width / height.

Parameters

$width
Can be just max width or an array containing both params.
$height
Max height.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# flip( string $type = 'horizontal' )

Flips an image. If PHP version is 5.5.0 or greater will use proper php gd imageflip method. Otherwise will fallback to convenienceflip.

Flips an image. If PHP version is 5.5.0 or greater will use proper php gd imageflip method. Otherwise will fallback to convenienceflip.

Parameters

$type
Type of flip, can be any of: horizontal, vertical, both

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# convenienceFlip( string $type = 'horizontal' )

Flip method for PHP versions < 5.5.0

Flip method for PHP versions < 5.5.0

Parameters

$type
Type of flip, can be any of: horizontal, vertical, both

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# create( integer $width = null, integer $height = null )

Creates an empty canvas.

Creates an empty canvas.

If no arguments are passed and we have previously created an image it will create a new canvas with the previous canvas size. Due to this, you can use this method to "empty" the current canvas.

Parameters

$width
Canvas width.
$height
Canvas height.

Returns

Elboletaire\Watimage\Image
protected resource
# imagecreate( integer $width, integer $height, boolean $transparency = true )

Creates an empty canvas.

Creates an empty canvas.

Parameters

$width
Canvas width.
$height
Canvas height.
$transparency
Whether or not to set transparency values.

Returns

resource
Image resource with the canvas.
protected resource
# imagecopy( integer $dstW, integer $dstH, integer $srcX = 0, integer $srcY = 0, $srcW = false, $srcH = false )

Helper method for all resize methods and others that require imagecopyresampled method.

Helper method for all resize methods and others that require imagecopyresampled method.

Parameters

$dstW
New width.
$dstH
New height.
$srcX
Starting source point X.
$srcY
Starting source point Y.
$srcW
$srcH

Returns

resource
GD image resource containing the resized image.
public Elboletaire\Watimage\Image
# fill( mixed $color = '#fff' )

Fills current canvas with specified color.

Fills current canvas with specified color.

It works with newly created canvas. If you want to overwrite the current canvas you must first call create method to empty current canvas.

Parameters

$color
The color. Check out getColorArray for allowed formats.

Returns

Elboletaire\Watimage\Image
public integer
# color( mixed $color )

Allocates a color for the current image resource and returns it.

Allocates a color for the current image resource and returns it.

Useful for directly treating images.

Parameters

$color
The color. Check out getColorArray for allowed formats.

Returns

integer

Codecoverageignore

public Elboletaire\Watimage\Image
# crop( integer $x, integer $y = null, integer $width = null, integer $height = null )

Crops an image based on specified coords and size.

Crops an image based on specified coords and size.

You can pass arguments one by one or an array passing arguments however you like.

Parameters

$x
X position where start to crop.
$y
Y position where start to crop.
$width
New width of the image.
$height
New height of the image.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# blur( mixed $type = null, integer $passes = 1 )

Blurs the image.

Blurs the image.

Parameters

$type
Type of blur to be used between: gaussian, selective.
$passes
Number of times to apply the filter.

Returns

Elboletaire\Watimage\Image

Throws

Elboletaire\Watimage\Exception\InvalidArgumentException
public Elboletaire\Watimage\Image
# brightness( integer $level )

Changes the brightness of the image.

Changes the brightness of the image.

Parameters

$level
Brightness value; range between -255 & 255.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# colorize( mixed $color )

Like grayscale, except you can specify the color.

Like grayscale, except you can specify the color.

Parameters

$color
Color in any format accepted by Normalize::color

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# contrast( integer $level )

Changes the contrast of the image.

Changes the contrast of the image.

Parameters

$level
Use for adjunting level of contrast (-100 to 100)

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# edgeDetection( )

Uses edge detection to highlight the edges in the image.

Uses edge detection to highlight the edges in the image.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# emboss( )

Embosses the image.

Embosses the image.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# grayscale( )

Applies grayscale filter.

Applies grayscale filter.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# meanRemove( )

Uses mean removal to achieve a "sketchy" effect.

Uses mean removal to achieve a "sketchy" effect.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# negate( )

Reverses all colors of the image.

Reverses all colors of the image.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# pixelate( integer $blockSize = 3, boolean $advanced = false )

Pixelates the image.

Pixelates the image.

Parameters

$blockSize
Block size in pixels.
$advanced
Set to true to enable advanced pixelation.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# sepia( integer $alpha = 0 )

A combination of various effects to achieve a sepia like effect.

A combination of various effects to achieve a sepia like effect.

TODO: Create an additional class with instagram-like effects and move it there.

Parameters

$alpha
Defines the transparency of the effect: from 0 to 100

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# smooth( integer $level )

Makes the image smoother.

Makes the image smoother.

Parameters

$level
Level of smoothness, between -15 and 15.

Returns

Elboletaire\Watimage\Image
public Elboletaire\Watimage\Image
# vignette( float $size = 0.7, float $level = 0.8 )

Adds a vignette to image.

Adds a vignette to image.

Parameters

$size
Size of the vignette, between 0 and 10. Low is sharper.
$level
Vignete transparency, between 0 and 1

Returns

Elboletaire\Watimage\Image

Link

http://php.net/manual/en/function.imagefilter.php#109809
public Elboletaire\Watimage\Image
# setQuality( integer $quality )

Sets quality for gif and jpg files.

Sets quality for gif and jpg files.

Parameters

$quality
A value from 0 (zero quality) to 100 (max quality).

Returns

Elboletaire\Watimage\Image

Codecoverageignore

public Elboletaire\Watimage\Image
# setCompression( integer $compression )

Sets compression for png files.

Sets compression for png files.

Parameters

$compression
A value from 0 (no compression, not recommended) to 9.

Returns

Elboletaire\Watimage\Image

Codecoverageignore

public Elboletaire\Watimage\Image
# setImage( resource $image )

Allows you to set the current image resource.

Allows you to set the current image resource.

This is intented for use it in conjuntion with getImage.

Parameters

$image
Image resource to be set.

Returns

Elboletaire\Watimage\Image

Throws

Exception
If given image is not a GD resource.
public array
# calculateCropMeasures( string|Elboletaire\Watimage\Image $croppedFile, mixed $ox, integer $oy = null, integer $dx = null, integer $dy = null )

Useful method to calculate real crop measures. Used when you crop an image which is smaller than the original one. In those cases you can call calculateCropMeasures to retrieve the real $ox, $oy, $dx & $dy of the image to be cropped.

Useful method to calculate real crop measures. Used when you crop an image which is smaller than the original one. In those cases you can call calculateCropMeasures to retrieve the real $ox, $oy, $dx & $dy of the image to be cropped.

Note that you need to set the destiny image and pass the smaller (cropped) image to this function.

Parameters

$croppedFile
The cropped image.
$ox
Origin X.
$oy
Origin Y.
$dx
Destiny X.
$dy
Destiny Y.

Returns

array
public resource
# getImage( )

Returns image resource, so you can use it however you wan.

Returns image resource, so you can use it however you wan.

Returns

resource

Codecoverageignore

public array
# getMetadata( )

Returns metadata for current image.

Returns metadata for current image.

Returns

array

Codecoverageignore

public static array
# getMetadataFromFile( string $filename )

Gets metadata information from given $filename.

Gets metadata information from given $filename.

Parameters

$filename
File path

Returns

array
protected
# getMetadataForImage( )

Loads metadata to internal variables.

Loads metadata to internal variables.

Codecoverageignore

protected string
# getMimeFromExtension( string $filename )

Gets mime for an image from its extension.

Gets mime for an image from its extension.

Parameters

$filename
Filename to be checked.

Returns

string
Mime for the filename given.

Throws

Elboletaire\Watimage\Exception\InvalidExtensionException
protected
# updateMetadata( )

Updates current image metadata.

Updates current image metadata.

Codecoverageignore

protected
# updateSize( )

Resets width and height of the current image.

Resets width and height of the current image.

Codecoverageignore

protected
# vignetteEffect( float $size, float $level, integer $x, integer $y, array & $rgb )

Required by vignette to generate the propper colors.

Required by vignette to generate the propper colors.

Parameters

$size
Size of the vignette, between 0 and 10. Low is sharper.
$level
Vignete transparency, between 0 and 1
$x
X position of the pixel.
$y
Y position of the pixel.
$rgb
$rgb Current pixel olor information.

Codecoverageignore

Constants summary

integer COLOR_TRANSPARENT

Constant for the (deprecated) transparent color

Constant for the (deprecated) transparent color

# -1

Properties summary

protected string $filename

Current image location.

Current image location.

#
protected resource $image

Image GD resource.

Image GD resource.

#
protected array $metadata

Image metadata.

Image metadata.

# []
protected float $width

Current image width

Current image width

#
protected float $height

Current image height

Current image height

#
protected integer $quality

Image export quality for gif and jpg files.

Image export quality for gif and jpg files.

You can set it with setQuality or setImage methods.

# 80
protected integer $compression

Image compression value for png files.

Image compression value for png files.

You can set it with setCompression method.

# 9
Watimage API API documentation generated by ApiGen