# Images helper

The `images_helper.php` file provides helper functions to handle image paths efficiently. These functions ensure that images are correctly resized and assigned default values when necessary.

***

#### `addSizeToPath()`

**Purpose:**

This function appends a given size string before the file extension in an image path. It is useful for handling different image resolutions without modifying the original filenames.

**Parameters:**

* **`$path`** (string) – The original image file path.
* **`$size`** (string) – The size to be appended before the file extension (e.g., "150x150").

**Usage:**

```php
$imagePath = "/uploads/images/sample.jpg";
$resizedPath = addSizeToPath($imagePath, "150x150");

echo $resizedPath; 
// Output: "/uploads/images/sample_150x150.jpg"
```

`img_square()`

**Purpose:**

This function generates a square image URL (150x150) if the input contains a valid path. If no path is provided, it returns a default placeholder image.

**Parameters:**

* **`$item`** (array/object) – An object or array containing:
  * **`path`** (string) – The original image path.
  * **`resize`** (string, optional) – The resize option indicating a required transformation.

**Usage:**

```php
$item = ['path' => '/uploads/images/sample.jpg', 'resize' => '150x150'];

echo img_square($item); 
// Output: "/uploads/images/sample_150x150.jpg"
```

If the input does not contain a valid path:

```php
$item = ['path' => '', 'resize' => ''];
echo img_square($item);
// Output: "/uploads/assets/150x150.webp"
```

***

## `img_vertical()`

**Purpose:**

Similar to `img_square`, this function generates a vertically resized image URL (333x500). If no valid image is found, it returns a default placeholder image.

**Parameters:**

* **`$item`** (array/object) – An object or array containing:
  * **`path`** (string) – The original image path.
  * **`resize`** (string, optional) – The resize option indicating a required transformation.

**Usage:**

```php
$item = (object) ['path' => '/uploads/images/sample.jpg', 'resize' => '333x500'];
echo img_vertical($item); 
// Output: "/uploads/images/sample_333x500.jpg"
```

If the input does not contain a valid path:

```php
$item = ['path' => '', 'resize' => ''];
echo img_vertical($item);
// Output: "/uploads/assets/333x500.webp" 
```

{% hint style="success" %}
**Conclusion**

The `images_helper.php` file provides essential functions for managing image paths dynamically, ensuring that resized images are correctly referenced while providing fallback images when needed.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cmsfullform.com/cms/helpers/images-helper.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
