Creates new Image.
Image
__construct
(
string $fileName, [
resource $image =
null], [
Point $position =
null], [
Dimensions $size =
null])
-
string
$fileName: Image file name.
-
resource
$image: Image data.
-
Point
$position
-
Dimensions
$size
Creates the image buffer used by the skew functions.
string
createImageMatrix
([int $size = 0], &$ratio, int $ratio)
-
int
$size: Size of the matrix.
-
int
$ratio: Rescale ratio of this image (value is returned by this method)
-
&$ratio
Crops current image.
-
Point
$position: Position of the upper left point of the area to crop.
-
Dimensions
$dimensions: Size of the area to crop.
Deskews the image.
Image
deskew
([
int $backgroundColor =
-1], [
bool $turboMode =
true], [
bool $debugMode =
false])
-
int
$backgroundColor: Color of the background to use, or -1 (default) to use auto detection.
-
bool
$turboMode: Set true to enable turbo mode (may be less accurate).
-
bool
$debugMode: Set true to enable the debug mode.
Draws the Hough line.
Image
drawHoughLine
(
int $distance,
int $theta, [
$color =
111111])
-
int
$distance: Distance from the origin.
-
int
$theta: Angle in degrees.
-
$color
Finds different shapes in the image.
Image[]
findObjects
([int $sortMode = 1])
(Fast) Detects the background color of this image.
mixed
getBackgroundColor
([ $numberOfSamples = 1], [bool $turboMode = false], int $numberOfSampes)
-
int
$numberOfSampes: Number of detected colors (sorted by the propability).
-
bool
$turboMode: Set true to use faster alghoritm (slightly less accurate).
-
$numberOfSamples
Returns binary frame buffer of the current image.
In case of color/grayscale images, use Image::toBinary() first.
string
getBinaryBuffer
(resource $image)
-
resource
$image: Image to binarize.
Returns a number of bytes used to store a single row of the image binary buffer.
For example: 128 pixels = 16 bytes, 127 pixels = 16 bytes (127 bits of image + 1 bits of padding), 129 pixels = 17 bytes (129 bits of image + 7 bits of padding)
int
getByteWidth
()
Returns copy of this image.
Returns image dimensions.
Returns GD2 resource handle of this image.
resource
getGd2Handle
()
Gets image height.
int
getHeight
()
Creates an image histogram.
Image
getHistogram
([
int $channels =
0], [
int $color =
0], [
int $backgroundColor =
0xffffff], [
bool $turboMode =
true])
-
int
$channels: Channels to draw, possibilities: Channel::RGB (default), Channel::RED, Channel::GREEN, Channel::BLUE
-
int
$color: Foreground color.
-
int
$backgroundColor: Background color.
-
bool
$turboMode: Use turbo mode (less accurate).
Returns next power of two representation of the given number.
int
getNextPowerOfTwo
(int $number)
-
int
$number: Number to convert.
Returns a color of the pixel at the X,Y coordinates.
Color
getPixelColor
(
int $x,
int $y)
-
int
$x: X-coordinate of the pixel to check.
-
int
$y: Y-coordinate of the pixel to check.
Returns a RGB value of the pixel at the X,Y coordinates.
int
getPixelRgb
(int $x, int $y)
-
int
$x: X-coordinate of the pixel to check.
-
int
$y: Y-coordinate of the pixel to check.
Returns a color of the pixel at the coordinates described in the Point object.
-
Point
$position: Position of the pixel to check.
Returns a RGB value of the pixel at the coordinates described in the Point object.
int
getPointRgb
(
Point $position)
-
Point
$position: Position of the pixel to check.
Returns viewport's position.
Position
getPosition
()
Calculates the size of this image.
int[]
getSize
()
Detects the skew angle of this image using the Hough normal transform.
resource
getSkewAngle
([int $numberOfSamples = 1], [int $matrixSize = 128], [bool $debugMode = false], [int $returnMode = 1])
-
int
$numberOfSamples: Number of different angles to detect (sorted by a number of votes).
-
int
$matrixSize: Size of the pixel matrix used for detection, bigger matrix = slower, more accurate detection.
-
bool
$debugMode: Draw detected Hough lines on this image? Works only in $returnMode = 1, default: false
-
int
$returnMode: Return mode: 1 = array of detected angles (default), 2 = rendered transform results (Image instance), 3 = array of transform results
Returns a sub image of this image.
Creates a vector from a part of an image.
Vector
getVector
([
Point $position =
null], [
Dimensions $size =
null], [
bool $round =
false], [
int $colorMask =
0])
-
Point
$position: X,Y-coordinates of the left upper-most point of the image.
-
Dimensions
$size: Width and height of the image.
-
bool
$round: Round the values?
-
int
$colorMask: Color bitmask.
Gets image width.
int
getWidth
()
Detects if the binary buffer of this image is empty after conversion to two-colors mode.
Empty buffer may mean that the conversion failed.
bool
isBinaryBufferEmpty
([double $threshold = 0.01])
-
double
$threshold: The threshold.
Resizes this image.
Image
resize
(
mixed $widthOrDimensions, [
int $height =
null], [
bool $useResampling =
true])
-
mixed
$widthOrDimensions: New width (or Dimensions) of the this image.
-
int
$height: New height of this image (used only if $widthOrDimensions is not an instance of Dimensions class)
-
bool
$useResampling: Use resampling? Default: true (slower)
Resizes this image and keeps the image aspect.
Image
resizeAndKeepAspect
(
mixed $widthOrDimensions, [
int $height =
null], [
bool $useResampling =
true])
-
mixed
$widthOrDimensions: New width (or Dimensions) of the this image.
-
int
$height: New height of this image (used only if $widthOrDimensions is not an instance of Dimensions class)
-
bool
$useResampling: Use resampling? Default: true (slower)
Rotates image by a given angle.
Image
rotate
(
int $angle, [
int $backgroundColor =
-1])
-
int
$angle: Angle in degrees (not radians).
-
int
$backgroundColor: Backround color used to fill empty spaces after rotation (or -1 for autodetection).
Saves this image to the disk.
Image
saveAsGif
(
string $fileName)
-
string
$fileName: File name.
Saves this image to the disk.
Image
saveAsJpeg
(
string $fileName)
-
string
$fileName: File name.
Saves this image to the disk.
Image
saveAsPng
(
string $fileName)
-
string
$fileName: File name.
Sets a color of the pixel at the X,Y coordinates.
Image
setPixelColor
(
int $x,
int $y,
Color $color)
-
int
$x: X-coordinate of the pixel to set.
-
int
$y: Y-coordinate of the pixel to set.
-
Color
$color
Sets a RGB value of the pixel at the X,Y coordinates.
Image
setPixelRgb
(
int $x,
int $y,
$rgb)
-
int
$x: X-coordinate of the pixel to set.
-
int
$y: Y-coordinate of the pixel to set.
-
$rgb
Sets a color of the pixel at the coordinates described in the Point object.
-
Point
$position: Position of the pixel to set.
-
Color
$color
Sets a RGB value of the pixel at the coordinates described in the Point object.
Image
setPointRgb
(
$position,
$rgb)
-
Point
$position: Position of the pixel to set.
-
$rgb
Displays the image.
Image
show
([
bool $die =
false])
-
bool
$die: Die after displaying an image? Default: false
Reduces color palette of this image to two colors (1 = pixel set, 0 = background).
Image
toBinary
([
bool $useEdgeDetection =
false])
-
bool
$useEdgeDetection: Use edge detection before converting to two colors?
Converts this image to grayscale.
Reverses all colors of the image.
Uses median filter to reduce image noise.
Image
useMedian
([
int $maskWidth =
3], [
int $maskHeight =
3])
-
int
$maskWidth: Width of the median mask (default: 3)
-
int
$maskHeight: Height of the median mask (default: 3)