October\Rain\Resize\Resizer

Resizer for images

Protected properties

protected Resource $file

The symfony uploaded file object.

protected string $extension

extension of the uploaded file

protected string $mime

mime type of the uploaded file

protected Resource $image

image (on disk) that's being resized

protected Resource $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 void __construct(mixed $file)

__construct instantiates the Resizer and receives the path to an image we're working with

Parameters
  • mixed $file - The file array provided by Laravel's Input::file('field_name') or a path to a file

public void crop(int $cropStartX, int $cropStartY, int $newWidth, int $newHeight, int $srcWidth=NULL, int $srcHeight=NULL)

Crops an image from its center

Parameters
  • int $cropStartX - Start on X axis
  • int $cropStartY - Start on Y axis
  • int $newWidth - The new width
  • int $newHeight - The new height
  • int $srcWidth - Source area width.
  • int $srcHeight - Source area height.

public static Resizer open(mixed $file)

Static call, Laravel style. Returns a new Resizer object, allowing for chainable calls

Parameters
  • mixed $file - The file array provided by Laravel's Input::file('field_name') or a path to a file

public void reset()

reset the image back to the original.

public void resize(int $newWidth, int $newHeight, array $options=array())

resize and/or crop an image

Parameters
  • int $newWidth - The width of the image
  • int $newHeight - The height of the image
  • array $options - A set of resizing options

public void save(string $savePath)

save the image based on its file type.

Parameters
  • string $savePath - Where to save the image

public void setOptions($options)

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)
Parameters
  • $options

public void sharpen(int $sharpness)

sharpen the image across a scale of 0 - 100

Parameters
  • int $sharpness

Protected methods

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

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

Parameters
  • int $newWidth - The width of the image
  • int $newHeight - The height of the image

protected int getHeight()

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

protected void getOptimalCrop(int $newWidth, int $newHeight)

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

Parameters
  • int $newWidth - The width of the image
  • int $newHeight - The height of the image

protected mixed getOption(string $option)

getOption gets an individual resizer option

Parameters
  • string $option - Option name to get

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

getOrientation receives the image's exif orientation

Parameters
  • Symfony\Component\HttpFoundation\File\File $file

protected resource getRotatedOriginal()

getRotatedOriginal receives the original but rotated image according to exif orientation

protected void getSizeByAuto(int $newWidth, int $newHeight)

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

Parameters
  • int $newWidth - The width of the image
  • int $newHeight - The height of the image

protected void getSizeByFit(int $maxWidth, int $maxHeight)

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

Parameters
  • int $maxWidth - The maximum width of the image
  • int $maxHeight - The maximum height of the image

protected int getSizeByFixedHeight(int $newHeight)

getSizeByFixedHeight returns the width based on the image height

Parameters
  • int $newHeight - The height of the image

protected int getSizeByFixedWidth(int $newWidth)

Returns the height based on the image width

Parameters
  • int $newWidth - The width of the image

protected int getWidth()

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

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

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

Parameters
  • Symfony\Component\HttpFoundation\File\File $file - File instance

protected void retainImageTransparency($img)

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

Parameters
  • $img

protected void setOption(string $option, mixed $value)

setOption sets an individual resizer option

Parameters
  • string $option - Option name to set
  • mixed $value - Option value to set