image_processing.php
Image processing functions
Functions to allow upload and resizing of images.
Table of Contents
Functions
- upload_file() : bool
- Upload a file from the provided path to the given resource
- extract_exif_comment() : bool
- Extract and process EXIF, IPTC, and FITS metadata for a resource.
- iptc_return_utf8() : string
- Convert IPTC metadata text to UTF-8 encoding.
- create_previews() : bool
- Generate previews for a resource, including thumbnails and alternative image sizes.
- extract_mean_colour() : void
- Calculate and update the mean color values for a resource image.
- update_portrait_landscape_field() : void
- Update the portrait or landscape orientation field for a resource.
- get_colour_key() : string
- Generate a color key for an image based on dominant colors.
- tweak_preview_images() : bool
- Apply rotation and gamma adjustments to all preview images of a resource.
- tweak_wm_preview_images() : bool
- Apply rotation and gamma adjustments to all watermarked preview images of a resource.
- AltImageRotate() : resource
- Rotate an image resource by a specified angle without using built-in rotation functions.
- base64_to_jpeg() : void
- Convert a base64-encoded image to a JPEG file.
- extract_indd_pages() : array<string|int, mixed>|bool
- Extracts JPG previews from INDD files when these have been set with a preview Note: it requires ExifTool >= 9.50
- generate_file_checksum() : bool
- Generate or update the checksum for a resource file.
- clear_file_checksum() : bool
- Clear the checksum value for a specified resource.
- check_duplicate_checksum() : array<string|int, mixed>
- Check for duplicate files based on checksum.
- upload_preview() : bool
- Upload and generate previews for a resource.
- extract_text() : bool
- Extract text from the resource and save to the configured field
- get_image_orientation() : int
- Get the orientation of an image file using ExifTool.
- AutoRotateImage() : bool
- Automatically rotate an image based on its orientation metadata.
- extract_icc_profile() : bool
- Provides ability to extract the ICC profile for a specified resource/ alternative file
- extract_icc() : bool
- Extracts the ICC profile from an image file using ImageMagick.
- get_imagemagick_version() : mixed
- Retrieves the version of ImageMagick installed on the system.
- calculate_image_dimensions() : array<string|int, mixed>
- Function used to get new width & height for an image in order to maintain aspect ratio while it will fit within a desired dimension.
- upload_file_by_url() : bool
- Upload file from a URL and add it to a resource.
- delete_previews() : mixed
- Delete all preview files for specified resource id or resource data array
- getFileDimensions() : array<string|int, mixed>
- Get dimensions of image file
- getSvgSize() : array<string|int, mixed>
- Get SVG size by reading the file and looking for dimensions at either width and height OR at Viewbox attribute(s)
- convertSvgLengthToPx() : int|null
- Convert SVG length/width dimension to px size at 96DPI
- replace_preview_from_resource() : bool
- Replace preview image with preview image from another resource/alternaive file
- get_preview_source_file() : string
- Get the source file to use for creating a preview
- compute_tiles_at_scale_factor() : array<string|int, mixed>
- Compute image tile regions based on a scale factor.
- transform_file() : bool
- Perform the requested action on the original file to create a new file
- remove_video_previews() : void
- For a given resource reference, remove the video pre size and all snapshots.
- start_previews() : int
- Create preview sizes via create_previews() and/or generate jobs as necessary
- get_sizes_to_generate() : array<string|int, mixed>|bool
- Get an array of preview size IDs to generate
- create_image_alternatives() : bool
- Generates alternative image files for a specified resource.
- is_valid_imagemagick_color() : bool
- Input validation helper function for ImageMagick's color values (e.g. blue, #ddddff and rgb(255,255,255))
- can_apply_icc_profile() : bool
- With $icc_extraction enabled, determine whether we should apply the icc profile that has been found.
- transform_apply_icc_profile() : array<string|int, mixed>
- Check if system is using ICC profiles and prepare ImageMagick command for use by transform_file() to enable system wide configuration for $icc_extraction to be applied when transforming a file, such as by format chooser or image tools.
- create_previews_using_im() : bool
- Generate previews for a resource using ImageMagick.
Functions
upload_file()
Upload a file from the provided path to the given resource
upload_file(int $ref[, bool $no_exif = false ][, bool $revert = false ][, bool $autorotate = false ][, string $file_path = "" ][, bool $after_upload_processing = false ][, bool $deletesource = true ]) : bool
Parameters
- $ref : int
-
Resource ID
- $no_exif : bool = false
-
Do not extract embedded metadata. False by default so data will be extracted
- $revert : bool = false
-
Delete all data and re-extract embedded data
- $autorotate : bool = false
-
Autorotate images - alters embedded orientation data in uploaded file
- $file_path : string = ""
-
Path to file
- $after_upload_processing : bool = false
-
Set to true will create an offline job to process the file
- $deletesource : bool = true
-
Delete resource after upload
Return values
boolextract_exif_comment()
Extract and process EXIF, IPTC, and FITS metadata for a resource.
extract_exif_comment(int $ref[, string $extension = "" ]) : bool
This function retrieves metadata from an image file, including EXIF, IPTC, and FITS metadata,
and updates the corresponding fields in the database. The process includes support for embedded
geolocation data, handling character encoding, and applying user-configurable options for specific fields.
If ExifTool is available, it is used for more comprehensive metadata extraction. Otherwise, the PHP
exif_read_data function is used as a fallback.
Parameters
- $ref : int
-
The resource reference ID.
- $extension : string = ""
-
(optional) The file extension for the image, used to validate processing compatibility.
Return values
bool —Returns false if the file does not exist; true on successful completion
iptc_return_utf8()
Convert IPTC metadata text to UTF-8 encoding.
iptc_return_utf8(string $text) : string
This function attempts to detect the character encoding of IPTC metadata text and converts it to UTF-8. If conversion is not possible due to missing libraries or if the encoding is unknown, the text is returned as-is. It uses a predefined list of character encodings for the conversion attempts.
Parameters
- $text : string
-
The IPTC metadata text to be converted.
Return values
string —The converted text in UTF-8 encoding, or the original text if conversion fails.
create_previews()
Generate previews for a resource, including thumbnails and alternative image sizes.
create_previews(int $ref[, bool $thumbonly = false ][, string $extension = "jpg" ][, bool $previewonly = false ][, bool $previewbased = false ][, int $alternative = -1 ][, bool $ignoremaxsize = false ][, bool $ingested = false ][, bool $checksum_required = true ][, array<string|int, mixed> $onlysizes = array() ][, bool $no_tiles = false ]) : bool
This function creates or updates image previews for a resource, such as thumbnails, based on the specified parameters. It supports a variety of configurations, including resizing with ImageMagick or GD library, generating checksums, and setting file attributes. If the file size exceeds a specified limit, it can queue the preview generation as an offline job.
Parameters
- $ref : int
-
The resource ID for which previews are generated.
- $thumbonly : bool = false
-
(optional) If
true, only the thumbnail will be generated. Default isfalse. - $extension : string = "jpg"
-
(optional) The file extension for the resource. Default is "jpg".
- $previewonly : bool = false
-
(optional) If
true, only preview images will be generated. Default isfalse. - $previewbased : bool = false
-
(optional) If
true, previews are generated based on existing previews rather than original files. Default isfalse. - $alternative : int = -1
-
(optional) If set, specifies an alternative file ID to generate previews for. Default is
-1. - $ignoremaxsize : bool = false
-
(optional) If
true, the file size limit for preview generation is ignored. Default isfalse. - $ingested : bool = false
-
(optional) If
true, marks the resource as already ingested into the system. Default isfalse. - $checksum_required : bool = true
-
(optional) If
true, generates a checksum for the file. Default istrue. - $onlysizes : array<string|int, mixed> = array()
-
(optional) Specifies an array of preview sizes to generate. If empty, all sizes are generated.
- $no_tiles : bool = false
-
(optional) Set to true to prevent creation of preview tiles (if enabled). Tiles would not be created where the preview source is a file created by preview_preprocessing.php.
Return values
bool —Returns true if previews were generated successfully; false otherwise.
extract_mean_colour()
Calculate and update the mean color values for a resource image.
extract_mean_colour(GdImage $image, int $ref) : void
Calculate and update the mean color values for a resource image.
This function calculates the mean red, green, and blue color values for a given image by sampling pixels in a grid pattern. It adjusts for brightness and excludes grayscale pixels to determine the dominant colors. Additionally, it updates the thumbnail dimensions and color key in the resource record.
Parameters
- $image : GdImage
-
The image resource to analyze for mean color.
- $ref : int
-
The resource ID for which the color data is updated.
update_portrait_landscape_field()
Update the portrait or landscape orientation field for a resource.
update_portrait_landscape_field(int $ref[, resource|null $image = null ]) : void
This function determines whether a resource image is in portrait, landscape, or square orientation and updates the specified field accordingly. If no image resource is provided, it attempts to load the thumbnail image for the resource.
Parameters
- $ref : int
-
The resource ID to update.
- $image : resource|null = null
-
(optional) An image resource for orientation analysis. If not provided, the function will load the resource thumbnail.
get_colour_key()
Generate a color key for an image based on dominant colors.
get_colour_key(GdImage $image) : string
This function extracts a color key that represents the dominant colors in an image, similar to a soundex code for colors. It maps the colors in the image to predefined color categories (e.g., black, white, red, etc.), calculates the closest match for each sampled pixel, and returns a five-character color key based on the most frequent colors.
Parameters
- $image : GdImage
-
The image resource to analyze.
Return values
string —A five-character string representing the dominant colors in the image.
tweak_preview_images()
Apply rotation and gamma adjustments to all preview images of a resource.
tweak_preview_images(int $ref, int $rotateangle, float $gamma[, string $extension = "jpg" ][, int $alternative = -1 ][, string $resource_ext = "" ]) : bool
This function adjusts the preview images of a resource by rotating or applying gamma correction. It primarily modifies the screen resolution preview, then scales and updates other preview sizes accordingly. For video resources, it also rotates snapshot images. Updates to rotation and gamma values are recorded in the database to allow future reconstruction of adjustments.
Parameters
- $ref : int
-
The resource ID for which previews are tweaked.
- $rotateangle : int
-
The angle in degrees to rotate the preview images.
- $gamma : float
-
The gamma correction factor (values > 1 to lighten, values < 1 to darken).
- $extension : string = "jpg"
-
(optional) The file extension for the preview images. Default is "jpg".
- $alternative : int = -1
-
(optional) The ID of an alternative file to tweak previews for. Default is
-1. - $resource_ext : string = ""
-
(optional) The file extension of the original resource, used for video snapshot rotation.
Return values
bool —Returns false if the main preview file does not exist; otherwise, updates previews and returns true.
tweak_wm_preview_images()
Apply rotation and gamma adjustments to all watermarked preview images of a resource.
tweak_wm_preview_images(int $ref, int $rotateangle, float $gamma[, string $extension = "jpg" ][, int $alternative = -1 ]) : bool
This function modifies watermarked preview images by applying a specified rotation angle and gamma correction factor. Each preview size defined in the database is processed, adjusting the watermarked version accordingly. The function resizes and updates each adjusted preview image.
Parameters
- $ref : int
-
The resource ID for which watermarked previews are tweaked.
- $rotateangle : int
-
The angle in degrees to rotate the watermarked preview images.
- $gamma : float
-
The gamma correction factor to apply (values > 1 to lighten, values < 1 to darken).
- $extension : string = "jpg"
-
(optional) The file extension for the preview images. Default is "jpg".
- $alternative : int = -1
-
(optional) The ID of an alternative file to tweak previews for. Default is
-1.
Return values
bool —Returns false if a watermarked file does not exist; otherwise, updates previews and returns true.
AltImageRotate()
Rotate an image resource by a specified angle without using built-in rotation functions.
AltImageRotate(GdImage $src_img, int $angle) : resource
This function manually rotates an image resource by 90, -90, or 180 degrees, creating a new image with the rotated pixels. If the angle is not one of these specified values, the original image is returned unmodified.
Parameters
- $src_img : GdImage
-
The source image resource to rotate.
- $angle : int
-
The angle in degrees to rotate the image (90, -90, or 180).
Return values
resource —The rotated image resource, or the original if the angle is unsupported.
base64_to_jpeg()
Convert a base64-encoded image to a JPEG file.
base64_to_jpeg(string $imageData, string $outputfile) : void
This function decodes a base64-encoded image string and saves it as a JPEG file.
Parameters
- $imageData : string
-
The base64-encoded image data.
- $outputfile : string
-
The path to save the decoded JPEG file.
Tags
extract_indd_pages()
Extracts JPG previews from INDD files when these have been set with a preview Note: it requires ExifTool >= 9.50
extract_indd_pages(string $filename) : array<string|int, mixed>|bool
Parameters
- $filename : string
Return values
array<string|int, mixed>|boolgenerate_file_checksum()
Generate or update the checksum for a resource file.
generate_file_checksum(int $resource, string $extension[, bool $anyway = false ]) : bool
This function calculates a unique checksum for a specified resource file. It either generates the checksum based on file contents and updates the resource record, or clears any existing checksum if the file does not exist. It also sets metadata indicating the checksum's last verification date and integrity status.
Parameters
- $resource : int
-
The ID of the resource for which the checksum is generated.
- $extension : string
-
The file extension of the resource.
- $anyway : bool = false
-
(optional) If
true, forces checksum generation regardless of configuration settings.
Return values
bool —Returns true if the checksum was generated; false if the file does not exist or was not generated.
clear_file_checksum()
Clear the checksum value for a specified resource.
clear_file_checksum(int $resource) : bool
Parameters
- $resource : int
-
The ID of the resource to clear the checksum for.
Return values
bool —Returns true if the checksum was cleared successfully; false if the resource ID is invalid.
check_duplicate_checksum()
Check for duplicate files based on checksum.
check_duplicate_checksum(string $filepath, int $replace_resource) : array<string|int, mixed>
This function calculates the checksum of a file and checks if any existing resources have the same checksum, indicating a possible duplicate. If a duplicate is found and the resource is not marked for replacement, the function returns the list of duplicate resource IDs.
Parameters
- $filepath : string
-
The file path of the file to check.
- $replace_resource : int
-
The resource ID to replace, if applicable, to avoid detecting it as a duplicate.
Return values
array<string|int, mixed> —An array of duplicate resource IDs, or an empty array if no duplicates are found.
upload_preview()
Upload and generate previews for a resource.
upload_preview(int $ref) : bool
This function uploads a user-provided preview image for a specified resource, ensuring the file is in JPEG format. After moving the file to its temporary location, it generates previews and cleans up the temporary file if not in use for transcoding.
Parameters
- $ref : int
-
The resource ID for which the preview is uploaded.
Return values
bool —Returns true if the preview upload and processing are successful, false if the file is not in JPEG format.
extract_text()
Extract text from the resource and save to the configured field
extract_text(int $ref, string $extension[, string $path = "" ]) : bool
Parameters
- $ref : int
-
Resource ref
- $extension : string
-
File extension
- $path : string = ""
-
Path can be set to use an alternate file, for example, in the case of unoconv
Tags
Return values
bool —Returns false on error else true.
get_image_orientation()
Get the orientation of an image file using ExifTool.
get_image_orientation(string $file) : int
This function retrieves the orientation metadata of an image file. If orientation information is not available, it attempts to retrieve the rotation metadata. The function uses ExifTool for the extraction and processes the result to return the orientation angle in degrees.
Parameters
- $file : string
-
The path to the image file.
Return values
int —The orientation angle in degrees (0, 90, 180, 270), or 0 if no orientation information is available.
AutoRotateImage()
Automatically rotate an image based on its orientation metadata.
AutoRotateImage(string $src_image[, int|bool $ref = false ]) : bool
This function uses ImageMagick to rotate an image to the correct orientation. If the image's orientation is determined using ExifTool, the function will rotate the image accordingly. It preserves custom metadata when applicable.
Parameters
- $src_image : string
-
The path to the source image that needs to be rotated.
- $ref : int|bool = false
-
The resource ID for the image; used to fetch orientation data if needed. Pass
falseif no resource ID is available.
Return values
bool —Returns true if the image was successfully rotated and saved, or false on failure.
extract_icc_profile()
Provides ability to extract the ICC profile for a specified resource/ alternative file
extract_icc_profile(int $ref, string $extension[, int $alternative = -1 ]) : bool
Parameters
- $ref : int
-
Resource ref
- $extension : string
-
Extension of the file
- $alternative : int = -1
-
Resource alternative ref. Default -1 as per get_resource_path() defintion
Tags
Return values
boolextract_icc()
Extracts the ICC profile from an image file using ImageMagick.
extract_icc(string $infile[, string $ref = '' ]) : bool
This function attempts to extract the ICC profile from the specified image file and saves it as a
separate file with the .icc extension. It checks if the ICC profile already exists and will
remove it before extraction. The function is compatible with both Windows and non-Windows
environments.
Parameters
- $infile : string
-
The path to the input image file from which to extract the ICC profile.
- $ref : string = ''
-
Optional. The resource ID associated with the image file. Used to determine the output path for the extracted ICC profile.
Tags
Return values
bool —Returns true if the ICC profile was successfully extracted and saved, or false on failure.
get_imagemagick_version()
Retrieves the version of ImageMagick installed on the system.
get_imagemagick_version([bool $array = true ]) : mixed
This function checks the version of ImageMagick by executing the convert command.
It can return the version information as either an array or a string, depending on the
value of the $array parameter.
Parameters
- $array : bool = true
-
Optional. If set to true, the function returns an array containing the major, minor, revision, and patch version numbers. If false, it returns a version string in the format "major.minor.revision-patch".
Return values
mixed —Returns an array with version numbers if $array is true, a version string if false, or false if ImageMagick is not installed or the version cannot be determined.
calculate_image_dimensions()
Function used to get new width & height for an image in order to maintain aspect ratio while it will fit within a desired dimension.
calculate_image_dimensions(string $image_path, int $target_width, int $target_height[, bool $enlarge_image = false ]) : array<string|int, mixed>
Parameters
- $image_path : string
-
The full path to the image (can be physical / URL)
- $target_width : int
- $target_height : int
- $enlarge_image : bool = false
-
Specify whether images smaller than our target should be enlarged or not. Default is FALSE
Return values
array<string|int, mixed> —New dimensions which can be used to resize the image and offset values client code can use for consistent visual display
upload_file_by_url()
Upload file from a URL and add it to a resource.
upload_file_by_url(int $ref[, bool $no_exif = false ][, bool $revert = false ][, bool $autorotate = false ][, string $url = "" ][, string $key = "" ]) : bool
Parameters
- $ref : int
-
Resource ID
- $no_exif : bool = false
-
=false Don't extract exif data - true to disable extraction
- $revert : bool = false
-
=false Delete all data and re-extract embedded data
- $autorotate : bool = false
-
=false Autorotate images - alters embedded orientation data in uploaded file
- $url : string = ""
-
="" File URL
- $key : string = ""
-
="" Optional key to distinguish betweeen simultaneous requests from same user with same filename
Return values
booldelete_previews()
Delete all preview files for specified resource id or resource data array
delete_previews(mixed $resource[, mixed $alternative = -1 ]) : mixed
Parameters
- $resource : mixed
-
array|integer Resource array or resource ID to delete preview files for
- $alternative : mixed = -1
getFileDimensions()
Get dimensions of image file
getFileDimensions(string $identify_fullpath, string $prefix, string $file, string $extension) : array<string|int, mixed>
Parameters
- $identify_fullpath : string
-
path to IM identify command
- $prefix : string
-
prefix - used by camera RAW files
- $file : string
-
path to file
- $extension : string
-
file extension
Return values
array<string|int, mixed> —width and height of image, elements are null if not possible e.g. not an image file
getSvgSize()
Get SVG size by reading the file and looking for dimensions at either width and height OR at Viewbox attribute(s)
getSvgSize(string $file_path) : array<string|int, mixed>
Parameters
- $file_path : string
-
Path to SVG file (should work with both a physical path and a URL)
Return values
array<string|int, mixed> —where first element is width and second is height represented as strings
convertSvgLengthToPx()
Convert SVG length/width dimension to px size at 96DPI
convertSvgLengthToPx(string $length) : int|null
Parameters
- $length : string
-
dimension to be converted
Return values
int|null —dimension in pixels, or null if cannot be converted
replace_preview_from_resource()
Replace preview image with preview image from another resource/alternaive file
replace_preview_from_resource(int $ref, int $previewresource, int $previewalt) : bool
Parameters
- $ref : int
-
Resource to replace preview image for
- $previewresource : int
-
Preview source resource ref
- $previewalt : int
-
Preview source resource alternative ref
Return values
boolget_preview_source_file()
Get the source file to use for creating a preview
get_preview_source_file(int $ref, string $extension, bool $previewonly, bool $previewbased, int $alternative, bool $ingested) : string
Parameters
- $ref : int
-
Resource ID
- $extension : string
-
Resource extension
- $previewonly : bool
-
Create previews only
- $previewbased : bool
-
Use existing preview as source
- $alternative : int
-
Alternative file reference
- $ingested : bool
-
Has file been ingested?
Return values
stringcompute_tiles_at_scale_factor()
Compute image tile regions based on a scale factor.
compute_tiles_at_scale_factor(int $sf, int $sw, int $sh) : array<string|int, mixed>
IMPORTANT: Please note that the origin position (0,0) is the upper left-most pixel of the image
Parameters
- $sf : int
-
Scale factor
- $sw : int
-
Source image width
- $sh : int
-
Source image height
Tags
Return values
array<string|int, mixed> —Returns array of tile data:
- id -> tile region identifier. Usually used as the size argument with get_resource_path()
- x -> represents the number of pixels from the origin (ie. position zero) on the horizontal axis
- y -> represents the number of pixels from the origin (ie. position zero) on the vertical axis
- w -> width of the region in pixels
- h -> height of the region in pixels
- row -> represents the row grid position of the region (used with DZI compliant systems)
- column -> represents the column grid position of the region (used with DZI compliant systems)
transform_file()
Perform the requested action on the original file to create a new file
transform_file(string $sourcepath, string $outputpath, array<string|int, mixed> $actions) : bool
Parameters
- $sourcepath : string
-
Path to source file
- $outputpath : string
- $actions : array<string|int, mixed>
-
Array of actions to perform
Return values
bool —Image created successfully?
remove_video_previews()
For a given resource reference, remove the video pre size and all snapshots.
remove_video_previews(int $resource) : void
Parameters
- $resource : int
-
Resource to remove video previews.
start_previews()
Create preview sizes via create_previews() and/or generate jobs as necessary
start_previews(int $ref[, string $extension = "" ]) : int
Parameters
- $ref : int
-
Resource ID
- $extension : string = ""
-
File extension
Return values
int —0 Preview creation failed 1 All previews have been created 2 Minimal previews created and offline jobs/scripts are required to create the full set of previews/image/video $alternatives
get_sizes_to_generate()
Get an array of preview size IDs to generate
get_sizes_to_generate(string $extension, array<string|int, mixed> $dimensions[, bool $thumbonly = false ][, bool $previewonly = false ][, array<string|int, mixed> $onlysizes = [] ][, bool $no_tiles = false ]) : array<string|int, mixed>|bool
Parameters
- $extension : string
-
File extension ('hpr' is only required for non-JPG images)
- $dimensions : array<string|int, mixed>
-
Image source dimensions in format [width,height]
- $thumbonly : bool = false
-
Generate 'thm' and 'col' only
- $previewonly : bool = false
-
Generate 'scr', 'pre', 'thm' and 'col' only
- $onlysizes : array<string|int, mixed> = []
-
Array of requested size IDs to generate
- $no_tiles : bool = false
-
Set to true to prevent creation of preview tiles (if enabled). Tiles would not be created where the preview source is a file created by preview_preprocessing.php.
Return values
array<string|int, mixed>|bool —Array of size IDs or false on failure.
create_image_alternatives()
Generates alternative image files for a specified resource.
create_image_alternatives(int $ref, array<string|int, mixed> $params[, bool $force = false ]) : bool
This function checks the existing alternative files and creates new ones based on the specified parameters. It can also force the creation of alternatives even if they already exist. It uses ImageMagick to process the images according to the specified configurations.
Parameters
- $ref : int
-
The resource ID for which alternatives are being generated.
- $params : array<string|int, mixed>
-
An associative array containing the following keys:
- file: The file path of the original image.
- extension: The extension of the original image (default is "jpg").
- previewonly: A boolean indicating if only previews should be created.
- previewbased: A boolean indicating if the alternatives are based on previews.
- ingested: A boolean indicating if the resource has been ingested (default is true).
- $force : bool = false
-
Optional. If set to true, will force the generation of alternative files even if they exist.
Return values
bool —Returns true if alternatives were generated successfully, false otherwise.
is_valid_imagemagick_color()
Input validation helper function for ImageMagick's color values (e.g. blue, #ddddff and rgb(255,255,255))
is_valid_imagemagick_color(string $val) : bool
Parameters
- $val : string
Tags
Return values
boolcan_apply_icc_profile()
With $icc_extraction enabled, determine whether we should apply the icc profile that has been found.
can_apply_icc_profile(string $original_file_path) : bool
Note: This doesn't prevent ICC profile extraction.
Parameters
- $original_file_path : string
-
Path to the original file from which the ICC profile was extracted.
Return values
booltransform_apply_icc_profile()
Check if system is using ICC profiles and prepare ImageMagick command for use by transform_file() to enable system wide configuration for $icc_extraction to be applied when transforming a file, such as by format chooser or image tools.
transform_apply_icc_profile(int $ref, string $original_file_path) : array<string|int, mixed>
Parameters
- $ref : int
-
Resource id.
- $original_file_path : string
-
Path to the original file for the resource.
Return values
array<string|int, mixed>create_previews_using_im()
Generate previews for a resource using ImageMagick.
create_previews_using_im(int $ref[, bool $thumbonly = false ][, string $extension = "jpg" ][, bool $previewonly = false ][, bool $previewbased = false ][, int $alternative = -1 ][, bool $ingested = false ][, array<string|int, mixed> $onlysizes = [] ][, bool $no_tiles = false ]) : bool
This function creates image previews for a resource by leveraging ImageMagick to handle resizing and generating thumbnails, medium, large, and custom-sized previews. It provides flexible options to control the generation process, such as limiting previews to specific sizes, applying watermarks, handling color profiles, and managing alternative files. The function includes extensive support for non-standard image formats and configurations.
Parameters
- $ref : int
-
The resource ID for which previews are generated.
- $thumbonly : bool = false
-
(optional) If
true, only the thumbnail will be generated. Default isfalse. - $extension : string = "jpg"
-
(optional) The file extension for the resource. Default is "jpg".
- $previewonly : bool = false
-
(optional) If
true, only preview images will be generated. Default isfalse. - $previewbased : bool = false
-
(optional) If
true, previews are generated based on existing previews rather than original files. Default isfalse. - $alternative : int = -1
-
(optional) Specifies an alternative file ID to generate previews for, if any. Default is
-1. - $ingested : bool = false
-
(optional) If
true, marks the resource as already ingested into the system. Default isfalse. - $onlysizes : array<string|int, mixed> = []
-
(optional) Specifies an array of preview sizes to generate. If empty, all sizes are generated.
- $no_tiles : bool = false
-
(optional) Set to true to prevent creation of preview tiles (if enabled). Tiles would not be created where the preview source is a file created by preview_preprocessing.php.
Return values
bool —Returns true if previews were generated successfully; false otherwise.