Contents

October\Rain\Resize\Resizer

Overview

Resizer for images

Available options are:

  • mode: Either exact, portrait, landscape, auto, fit, cover or crop.
  • offset: The offset of the crop = [ left, top ]
  • sharpen: Sharpen image, from 0 - 100 (default: 0)
  • interlace: Interlace image, Boolean: false (disabled: default), true (enabled)
  • quality: Image quality, from 0 - 100 (default: 90)

Protected Properties

protected FileObj $file

file the symfony uploaded file object

protected string $extension

extension of the uploaded file

protected string $mime

mime type of the uploaded file

protected GdImage $image

image (on disk) that's being resized

protected GdImage $originalImage

originalImage cached

protected int $width

width of the original image being resized

protected int $height

height of the original image being resized

protected int|null $orientation

orientation (Exif) of image

protected array $options

options used for resizing


Public Methods

public __construct()

public __construct(mixed $file): void

__construct instantiates the Resizer and receives the path to an image we're working with. The file can be either Input::file('field_name') or a path to a file

public static open()

public static open($file): October\Rain\Resize\Resizer 

open is a static constructor

public reset()

public reset(): static 

reset the image back to the original.

public resize()

public resize(
    int|null $width,
    int|null $height,
    array $options = []
): static 

resize and/or crop an image, specifying the new width and height of the destination image.

public save()

public save(string $savePath): void

save the image based on its file type.

public setOptions()

public setOptions($options): static 

setOptions sets resizer options

Protected Methods

protected buildEncoderOptions()

protected buildEncoderOptions(string $savePath): array 

buildEncoderOptions builds encoder options (quality, interlace/progressive) for saving.

protected getOption()

protected getOption(string $option): void

getOption gets an individual resizer option

protected openImage()

protected openImage(
    Symfony\Component\HttpFoundation\File\File $file
): mixed 

openImage opens a file, detect its mime-type and create an image resource from it