October\Rain\Resize\Resizer

Overview

Resizer for images


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 crop()

public crop(
    int $cropStartX,
    int $cropStartY,
    int $newWidth,
    int $newHeight,
    int $srcWidth = null,
    int $srcHeight = null
): October\Rain\Resize\Resizer 

Crops an image from its center

public static open()

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

open is a static constructor

public reset()

public reset(): October\Rain\Resize\Resizer 

reset the image back to the original.

public resize()

public resize(
    int $newWidth,
    int $newHeight,
    array $options = []
): October\Rain\Resize\Resizer 

resize and/or crop an image

public save()

public save(string $savePath): void

save the image based on its file type.

public setOptions()

public setOptions($options): October\Rain\Resize\Resizer 

setOptions sets resizer options. Available options are:

  • mode: Either exact, portrait, landscape, auto, fit 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)

public sharpen()

public sharpen(int $sharpness): October\Rain\Resize\Resizer 

sharpen the image across a scale of 0 - 100

Protected Methods

protected getDimensions()

protected getDimensions(int $newWidth, int $newHeight): array 

getDimensions returns the image dimensions based on the option that was chosen.

protected getHeight()

protected getHeight(): int 

getHeight receives the image's height while respecting the exif orientation

protected getOptimalCrop()

protected getOptimalCrop(int $newWidth, int $newHeight): array 

getOptimalCrop attempts to find the best way to crop. Whether crop is based on the image being portrait or landscape.

protected getOption()

protected getOption(string $option): mixed 

getOption gets an individual resizer option

protected getOrientation()

protected getOrientation(
    Symfony\Component\HttpFoundation\File\File $file
): int|null 

getOrientation receives the image's exif orientation

protected getRotatedOriginal()

protected getRotatedOriginal(): GdImage 

getRotatedOriginal receives the original but rotated image according to exif orientation

protected getSizeByAuto()

protected getSizeByAuto(int $newWidth, int $newHeight): array 

getSizeByAuto checks to see if an image is portrait or landscape and resizes accordingly.

protected getSizeByFit()

protected getSizeByFit(int $maxWidth, int $maxHeight): array 

getSizeByFit fits the image inside a bounding box using maximum width and height constraints.

protected getSizeByFixedHeight()

protected getSizeByFixedHeight(int $newHeight): int 

getSizeByFixedHeight returns the width based on the image height

protected getSizeByFixedWidth()

protected getSizeByFixedWidth(int $newWidth): int 

Returns the height based on the image width

protected getWidth()

protected getWidth(): int 

getWidth receives the image's width while respecting the exif orientation

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

protected retainImageTransparency()

protected retainImageTransparency($img): void

retainImageTransparency manipulates an image resource in order to keep transparency for PNG and GIF files.

protected setOption()

protected setOption(
    string $option,
    mixed $value
): October\Rain\Resize\Resizer 

setOption sets an individual resizer option