Oihana PHP System

ImageTrait uses trait:short

Table of Contents

Properties

$compression  : int
The default image compression of the output image.
$image_response_default_options  : array<string|int, mixed>
$imagick_response_default_options  : array<string|int, mixed>
$resize_options_default  : array<string|int, mixed>

Methods

fail()  : ResponseInterface|null
Formats a specific error status message with a code and an errors array representation of all errors.
getImageDimensions()  : array<string|int, mixed>|null
getImageHeight()  : int
getImagesRoot()  : string
getImageWidth()  : int
imageResponse()  : ResponseInterface
Returns an Image response
imagickResponse()  : ResponseInterface
Returns an Image response with options to transform the image before.
resize()  : string|Imagick|null
Resize an image.
shadow()  : string|Imagick|null
Apply a shadow over an image.
status()  : ResponseInterface|null
Outputs a response status message.
success()  : mixed
Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.

Properties

$compression

The default image compression of the output image.

public int $compression = \Imagick::COMPRESSION_JPEG

$image_response_default_options

protected array<string|int, mixed> $image_response_default_options = ['contentDisposition' => null, 'format' => 'jpg', 'useContentDisposition' => false, 'useContentLength' => true, 'useContentType' => true]

$imagick_response_default_options

protected array<string|int, mixed> $imagick_response_default_options = ['compression' => \Imagick::COMPRESSION_JPEG, 'quality' => 70, 'gray' => false, 'strip' => false]

$resize_options_default

protected array<string|int, mixed> $resize_options_default = ['maxHeight' => 1200, 'maxWidth' => 1920]

Methods

fail()

Formats a specific error status message with a code and an errors array representation of all errors.

public fail(ResponseInterface|null $response[, int|string|null $code = 400 ][, string|null $details = null ][, array<string|int, mixed> $options = [] ]) : ResponseInterface|null

Ex: A 'not acceptable' http request with a failed validation process

return $this->getError( $response , 406 , 'fields validation failed' , [ 'firstName' => 'firstName is required'  , 'lastName' => 'lastName must be a string' ] ] ) ;
``
Parameters
$response : ResponseInterface|null

The Response reference.

$code : int|string|null = 400

The status code of the response.

$details : string|null = null

The optional error message to overrides the default status message.

$options : array<string|int, mixed> = []

The optional array to inject in the json object (with an errors)

Return values
ResponseInterface|null

getImageDimensions()

public getImageDimensions(Imagick|string $image) : array<string|int, mixed>|null
Parameters
$image : Imagick|string
Tags
throws
ImagickException
Return values
array<string|int, mixed>|null

getImageHeight()

public getImageHeight(Imagick|string $image) : int
Parameters
$image : Imagick|string
Tags
throws
ImagickException
Return values
int

getImagesRoot()

public getImagesRoot() : string
Return values
string

getImageWidth()

public getImageWidth(Imagick|string $image) : int
Parameters
$image : Imagick|string
Tags
throws
ImagickException
Return values
int

imageResponse()

Returns an Image response

public imageResponse(ResponseInterface $response, string $file[, array<string|int, mixed> $options = [] ]) : ResponseInterface
Parameters
$response : ResponseInterface
$file : string
$options : array<string|int, mixed> = []
Return values
ResponseInterface

imagickResponse()

Returns an Image response with options to transform the image before.

public imagickResponse(ResponseInterface $response, mixed $image[, array<string|int, mixed> $options = [] ]) : ResponseInterface
Parameters
$response : ResponseInterface
$image : mixed
$options : array<string|int, mixed> = []
Return values
ResponseInterface

resize()

Resize an image.

public resize(Imagick|string|null $image[, int|null $w = null ][, int|null $h = null ][, array<string|int, mixed> $options = [] ]) : string|Imagick|null

Ex: ../image?resize=true&w=50&h=50

Parameters
$image : Imagick|string|null

The url of the image file or the Imagick object reference to transform.

$w : int|null = null
$h : int|null = null
$options : array<string|int, mixed> = []
Tags
throws
ImagickException
Return values
string|Imagick|null

shadow()

Apply a shadow over an image.

public shadow(Imagick|string|null $image[, string|null $value = null ]) : string|Imagick|null

Ex: ../image?shadow=true Ex: ../image?shadow=60,4,10,20

Parameters
$image : Imagick|string|null

The url of the image file or the Imagick object reference to transform.

$value : string|null = null
Tags
throws
ImagickException
Return values
string|Imagick|null

status()

Outputs a response status message.

public status(ResponseInterface|null $response[, mixed $message = Char::EMPTY ][, int|string|null $code = 200 ][, array<string|int, mixed>|null $options = null ]) : ResponseInterface|null
Parameters
$response : ResponseInterface|null
$message : mixed = Char::EMPTY

The message to send.

$code : int|string|null = 200

The status code.

$options : array<string|int, mixed>|null = null

The options to passed-in in the status definition.

Tags
example
return $this->getStatus( $response , 'bad request' , '405' );
Return values
ResponseInterface|null

success()

Outputs a success message with a JSON response. If the $response parameter is null, returns the $data parameter value.

public success(ServerRequestInterface|null $request, ResponseInterface|null $response[, mixed $data = null ][, array<string|int, mixed>|null $init = null ]) : mixed

Ex: return $this->success( $request , $response , $data , [ Output::PARAMS => $request->getParams() ] ) ;

Parameters
$request : ServerRequestInterface|null

The HTTP request reference.

$response : ResponseInterface|null

The HTTP Response reference.

$data : mixed = null

The data object to returns (output a JSON object).

$init : array<string|int, mixed>|null = null

An associative definition to initialize the output object with the optional properties :

    count (int) - The optional number of elements. owner (object|array) - The optional owner reference. options (array) - An associative array of optional properties to add in the output object. params (array) - The optional params to passed-in the getCurrentPath() method when the url option is null. status (int) - The optional status of the response. total (int) - The optional total number of elements. url (string) - The optional url to display.

        
On this page

Search results