Documentation

image_helper.php

Table of Contents

Functions

processUploadedImage()  : bool
Processes, resizes, and saves an uploaded image file.

Functions

processUploadedImage()

Processes, resizes, and saves an uploaded image file.

processUploadedImage(string $source_path, int $image_type, string $target_dir, string $target_filename, int $target_width) : bool

This function handles the resizing of an image to a specified width while automatically calculating the height to maintain the original aspect ratio. It supports JPEG and PNG formats and preserves transparency for PNG images.

Parameters
$source_path : string

The absolute path to the temporary source file (e.g., from $_FILES).

$image_type : int

The GD image type constant (IMAGETYPE_JPEG or IMAGETYPE_PNG).

$target_dir : string

The destination directory path (must include trailing slash).

$target_filename : string

The name of the file to save (including extension).

$target_width : int

The desired width of the resized image in pixels.

Return values
bool

True if the image was successfully processed and saved, false otherwise.


        
On this page

Search results