Contents

System\Classes\ResizeImages

Overview

ResizeImages is used for resizing image files


Protected Properties

protected array $availableSources

availableSources to get image paths

protected string $storageFolder

storageFolder is the name of the folder in the resources disk

protected string $storageUrl

storageUrl relative or absolute URL of the Library root folder.

protected static string $imageItemClass

imageItemClass to use for a single resize request. Override in a subclass and rebind system.resizer to customize the resizer output (filename, partition directory, cache key, etc).


Public Methods

public __construct()

public __construct(): void

__construct this instance

public getContents()

public getContents($cacheKey): void

getContents performs the resize and stores in on disk, creating a cache

public getPublicPath()

public getPublicPath($imageItem): void

getPublicPath returns the public address for the resources path

public getStoragePath()

public getStoragePath($imageItem): void

getStoragePath returns a relative storage path for the image

public getTempPath()

public getTempPath(): void

getTempPath returns an internal working path

public static instance()

public static instance(): static 

instance creates a new instance of this singleton

public static resetCache()

public static resetCache(): void 

resetCache resets the resizer cache

public static resize()

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

resize generates and returns a thumbnail URL path

Protected Methods

protected getCache()

protected getCache(string $cacheKey): array 

getCache looks up information about a cache identifier.

protected getExistsCacheKey()

protected getExistsCacheKey($filePath): string 

getExistsCacheKey builds a key for caching the exists check

protected getModifiedCacheKey()

protected getModifiedCacheKey($filePath): string 

getModifiedCacheKey builds a key for caching the last modified check

protected getResizedUrl()

protected getResizedUrl($outputFilename = 'undefined.css'): void

protected getSourcePathForResize()

protected getSourcePathForResize($realSourcePath, $tempSourcePath): void

getSourcePathForResize creates a temp copy of external files in the local filesystem

protected hasFile()

protected hasFile($imageItem): bool 

hasFile checks the file exists on the storage device and is newer than the source

protected isCanonicalHost()

protected isCanonicalHost($host): bool 

isCanonicalHost rejects non-canonical numeric IPv4 spellings (leading-zero/octal, hex, abbreviated, integer) that dns_get_record and libc getaddrinfo parse differently

protected isLocalStorage()

protected isLocalStorage(): void

isLocalStorage returns true if the storage engine is local

protected isStaleFile()

protected isStaleFile($imageItem, $filePath): bool 

isStaleFile returns true when the source file was modified after the resized image was generated, detecting files replaced in-place under the same name

protected makeCacheKey()

protected makeCacheKey($cacheKey): string 

makeCacheKey prefixes an identifier with the current cache generation. Resetting the cache bumps the generation instead of enumerating and deleting every stored identifier.

protected normalizeIpForRangeCheck()

protected normalizeIpForRangeCheck($ip): string|null 

normalizeIpForRangeCheck converts IPv4-mapped and IPv4-compatible IPv6 addresses to their embedded IPv4 form so private-range checks apply

protected prepareRequest()

protected prepareRequest(
    $image,
    $width = null,
    $height = null,
    $options = []
): void

prepareRequest checks if an image has been resized before and returns the URL, otherwise the performs the resize by passing to a route that ends up at getContents

protected processImage()

protected processImage($cacheKey): void 

processImage performs the resize and stores it on disk

protected putCache()

protected putCache(string $cacheKey, array $cacheInfo): bool 

putCache stores information about a asset collection against a cache identifier.

protected validateExternalImageHost()

protected validateExternalImageHost($url): bool 

validateExternalImageHost rejects URLs whose scheme is not http(s) or whose host resolves to a loopback, private, link-local, or reserved address

protected validateExternalImageUrl()

protected validateExternalImageUrl($url): bool 

validateExternalImageUrl checks if an external URL has a valid image extension

protected validateImageContents()

protected validateImageContents($contents): bool 

validateImageContents checks the fetched bytes are actually an image by MIME type