CropEntropy

Extends \stojg\crop\Crop

CropEntropy

This class finds the a position in the picture with the most energy in it.

Energy is in this case calculated by this

  1. Take the image and turn it into black and white
  2. Run a edge filter so that we're left with only edges.
  3. Find a piece in the picture that has the highest entropy (i.e. most edges)
  4. Return coordinates that makes sure that this piece of the picture is not cropped 'away'

Methods

get special offset for class

getSpecialOffset(\Imagick $original, int $targetWidth, int $targetHeight) : array

Arguments

$original

\Imagick

$targetWidth

int

$targetHeight

int

Response

array

Get the topleftX and topleftY that will can be passed to a cropping method.

getEntropyOffsets(\Imagick $original, int $targetWidth, int $targetHeight) : array

Arguments

$original

\Imagick

$targetWidth

int

$targetHeight

int

Response

array

Get the offset of where the crop should start

getOffsetFromEntropy(\Imagick $originalImage, $targetWidth, int $targetHeight) : array

Arguments

$originalImage

\Imagick

$targetWidth

$targetHeight

int

Response

array

slice

slice(mixed $image, mixed $originalSize, mixed $targetSize, mixed $axis) : void
access

protected

Arguments

$image

mixed

$originalSize

mixed

$targetSize

mixed

$axis

mixed

h=horizontal, v = vertical

getLimit get image limit. Used to set "uncropable" limit

getLimit(string $position, int $offset) : int|null
access

protected

Arguments

$position

string

(top|bottom|left|right)

$offset

int

Response

int|null

getSafeZoneList

getSafeZoneList() : array
access

protected

Response

array

Calculate the entropy for this image.

grayscaleEntropy(\Imagick $image) : float

A higher value of entropy means more noise / liveliness / color / business

see

Arguments

$image

\Imagick

Response

float

Find out the entropy for a color image

colorEntropy(\Imagick $image) : float

If the source image is in color we need to transform RGB into a grayscale image so we can calculate the entropy more performant.

Arguments

$image

\Imagick

Response

float

Profiling method

start() 
inherited static

Profiling method

mark() : string
inherited static

Response

string

__construct

__construct(string $imagePath) 
inherited

Arguments

$imagePath

string

  • The path to an image to load. Paths can include wildcards for file names, or can be URLs.

Get the area in pixels for this image

area(\Imagick $image) : int
inherited

Arguments

$image

\Imagick

Response

int

Resize and crop the image so it dimensions matches $targetWidth and $targetHeight

resizeAndCrop(int $targetWidth, int $targetHeight) : boolean|\Imagick
inherited

Arguments

$targetWidth

int

$targetHeight

int

Response

boolean|\Imagick

Returns width and height for resizing the image, keeping the aspect ratio and allow the image to be larger than either the width or height

getSafeResizeOffset(\Imagick $image, int $targetWidth, int $targetHeight) : array
inherited

Arguments

$image

\Imagick

$targetWidth

int

$targetHeight

int

Response

array

Returns a YUV weighted greyscale value

rgb2bw(int $r, int $g, int $b) : int
inherited
see

Arguments

$r

int

$g

int

$b

int

Response

int

getEntropy

getEntropy(array $histogram, int $area) : float
inherited

Arguments

$histogram

array

  • a value[count] array

$area

int

Response

float

Constants


                                
inherited


                                
inherited

Properties

Timer used for profiler / debugging

start_time
inherited static
var

originalImage

originalImage
inherited
var