Images and Media
Images Helper
The Images class provides helper methods for working with images.
Namespace: Medialight\Textstem\Helpers
imageFromAsset
Creates an HTML img tag from an asset.
public static function imageFromAsset($asset, $attributes = [])
Parameters:
$asset(object): The asset object.$attributes(array): Additional attributes for the img tag.
Returns:
- (string): The HTML img tag.
pictureFromAsset
Creates an HTML picture tag from an asset.
public static function pictureFromAsset($asset, $attributes = [])
Parameters:
$asset(object): The asset object.$attributes(array): Additional attributes for the img tag inside the picture tag.
Returns:
- (string): The HTML picture tag.
getExifThumb
Extracts an EXIF thumbnail from an image.
public static function getExifThumb($path, $thumbPath)
Parameters:
$path(string): The path to the image.$thumbPath(string): The path to save the thumbnail to.
Returns:
- (mixed): The result of saving the thumbnail, or null if no thumbnail was found.
MediaAsset Helper
The MediaAsset class provides helper methods for working with media assets.
Namespace: Medialight\Textstem\Helpers
loadForPath
Loads an asset for a given path.
public static function loadForPath($srcPath, $alwaysCreate = false)
Parameters:
$srcPath(string): The source path of the asset.$alwaysCreate(bool): Whether to always create a new asset if one doesn't exist. Default is false.
Returns:
- (mixed): The asset object or null if not found and not created.
checkAssetFile
Checks if an asset file exists.
public static function checkAssetFile($asset): bool
Parameters:
$asset(object): The asset object to check.
Returns:
- (bool): True if the asset file exists, false otherwise.
checkAssetThumb
Checks if an asset thumbnail exists.
public static function checkAssetThumb($asset)
Parameters:
$asset(object): The asset object to check.
Returns:
- (mixed): The result of checking the thumbnail.
checkThumb
Checks if a thumbnail exists for a given path.
public static function checkThumb($srcPath, $thumbPath = null, $useExistingIfExists = true, $silent = false, $x = null, $y = null)
Parameters:
$srcPath(string): The source path of the image.$thumbPath(string|null): The path to save the thumbnail to. Default is null.$useExistingIfExists(bool): Whether to use an existing thumbnail if it exists. Default is true.$silent(bool): Whether to suppress errors. Default is false.$x(int|null): The width of the thumbnail. Default is null.$y(int|null): The height of the thumbnail. Default is null.
Returns:
- (mixed): The result of checking or creating the thumbnail.
thumbPath
Gets the thumbnail path for a given source path.
public static function thumbPath($srcPath): string
Parameters:
$srcPath(string): The source path of the image.
Returns:
- (string): The thumbnail path.
makeThumb
Creates a thumbnail for a given image path.
public static function makeThumb($srcImgPath): string
Parameters:
$srcImgPath(string): The source path of the image.
Returns:
- (string): The path of the created thumbnail.
createAssetForFile
Creates an asset for a given file path.
public static function createAssetForFile($file_path, $info = null)
Parameters:
$file_path(string): The path of the file.$info(array|null): Additional information about the file. Default is null.
Returns:
- (mixed): The created asset object.
assetTypeFromMime (MediaAsset)
Determines the asset type from a MIME type.
public static function assetTypeFromMime($mime)
Parameters:
$mime(string): The MIME type of the asset.
Returns:
- (string): The asset type.
Smartcrop Helper
The Smartcrop class provides helper methods for intelligently cropping images.
Namespace: Medialight\Textstem\Helpers
__construct (Smartcrop)
Constructor that takes an image and options.
public function __construct(Image $image, array $options)
Parameters:
$image(Image): The image to crop.$options(array): Options for the cropping algorithm.
Returns:
- (void)
canvasImageScale
Scales the canvas image.
public function canvasImageScale()
Returns:
- (mixed): The scaled canvas image.
analyse
Analyzes the image.
public function analyse()
Returns:
- (mixed): The analysis result.
downSample
Downsamples the image.
public function downSample($factor)
Parameters:
$factor(int): The factor to downsample by.
Returns:
- (mixed): The downsampled image.
edgeDetect
Detects edges in the image.
public function edgeDetect($x, $y, $w, $h)
Parameters:
$x(int): The x-coordinate.$y(int): The y-coordinate.$w(int): The width.$h(int): The height.
Returns:
- (mixed): The edge detection result.
skinDetect
Detects skin in the image.
public function skinDetect($r, $g, $b, $lightness)
Parameters:
$r(int): The red component.$g(int): The green component.$b(int): The blue component.$lightness(float): The lightness value.
Returns:
- (mixed): The skin detection result.
saturationDetect
Detects saturation in the image.
public function saturationDetect($r, $g, $b, $lightness)
Parameters:
$r(int): The red component.$g(int): The green component.$b(int): The blue component.$lightness(float): The lightness value.
Returns:
- (mixed): The saturation detection result.
generateCrops
Generates crop options.
public function generateCrops()
Returns:
- (array): The generated crop options.
score
Scores a crop option.
public function score($output, $crop)
Parameters:
$output(array): The output data.$crop(array): The crop option to score.
Returns:
- (float): The score of the crop option.
importance
Calculates the importance of a pixel.
public function importance($crop, $x, $y)
Parameters:
$crop(array): The crop option.$x(int): The x-coordinate.$y(int): The y-coordinate.
Returns:
- (float): The importance value.
thirds
Applies the rule of thirds.
public function thirds($x)
Parameters:
$x(float): The position value.
Returns:
- (float): The thirds value.
sample
Samples a pixel.
public function sample($x, $y)
Parameters:
$x(int): The x-coordinate.$y(int): The y-coordinate.
Returns:
- (array): The sampled pixel data.
cie
Converts RGB to CIE.
public function cie($r, $g, $b)
Parameters:
$r(int): The red component.$g(int): The green component.$b(int): The blue component.
Returns:
- (float): The CIE value.
skinColor
Detects skin color.
public function skinColor($r, $g, $b)
Parameters:
$r(int): The red component.$g(int): The green component.$b(int): The blue component.
Returns:
- (float): The skin color value.
saturation
Calculates saturation.
public function saturation($r, $g, $b)
Parameters:
$r(int): The red component.$g(int): The green component.$b(int): The blue component.
Returns:
- (float): The saturation value.
Thumbnails Helper
The Thumbnails class provides helper methods for working with thumbnail sizes.
Namespace: Medialight\Textstem\Helpers
sizeRules
Returns size rules for a given size name.
public static function sizeRules($sizeName)
Parameters:
$sizeName(string): The name of the size to get rules for.
Returns:
- (object): An object with width, height, and fit properties.
VideoHelper
The VideoHelper class is a Laravel facade backed by Medialight\Textstem\Services\VideoHelperService (accessor: videohelper). It wraps FFProbe for video metadata extraction.
Namespace: Medialight\Textstem\Helpers
Requires the FFProbe class to be available (provided by php-ffmpeg/php-ffmpeg).
isEnabled
Checks whether FFProbe is available in the current environment.
public static function isEnabled(): bool
Returns:
- (bool): True if the
FFProbeclass exists and video inspection is available.
getVideoInfo
Retrieves width, height, and duration metadata for a video file.
public static function getVideoInfo(string $videoURL): array
Parameters:
$videoURL(string): Path or URL to the video file.
Returns:
- (array):
['width' => int, 'height' => int, 'duration' => float], or an empty array if FFProbe is unavailable.