Server Side Programming Articles

Page 1010 of 2109

How to crop an image to the given rectangle using imagecrop() function using PHP?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 3K+ Views

imagecrop() is an inbuilt function in PHP that is used to crop an image to the given rectangle. It crops the image from the given rectangle area and returns the output image. The given image is not modified. Syntax resource imagecrop ($image, $rect) Parameters imagecrop() takes two parameters, $image and $rect. $image − It is the parameter returned by the image creation functions, such as imagecreatetruecolor(). It is used to create the size of an image. $rect − The cropping rectangle is an array with keys x, y, width, and height. ...

Read More

How to crop an image automatically using imagecropauto() function in PHP?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 1K+ Views

The imagecropauto() function is an inbuilt PHP function that automatically crops an image using one of the available modes to remove unwanted borders or backgrounds. Note: This function requires the GD extension. Install it using: sudo apt-get install php-gd (Linux) or enable it in php.ini (Windows/XAMPP). Syntax resource imagecropauto(resource $image, int $mode, float $threshold, int $color) Parameters imagecropauto() accepts four parameters − $image, $mode, $threshold, and $color. $image − The image resource to be cropped. $mode − Optional. Specifies the crop mode: IMG_CROP_DEFAULT − Works like IMG_CROP_TRANSPARENT mode. ...

Read More

How to destroy an image in PHP using imagedestroy() function?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 754 Views

The imagedestroy() function is an inbuilt PHP function used to destroy an image resource and free any memory associated with it. This function is essential for preventing memory leaks when working with image processing in PHP. Syntax bool imagedestroy(resource $image) Parameters $image − An image resource created by one of the image creation functions like imagecreatetruecolor() or imagecreatefrompng(). Return Value Returns true on success or false on failure. Example 1 − Creating and Destroying a Simple Image Here's a basic example of creating an image and then destroying it ? ...

Read More

How to create a new image from a JPEG file using the imagecreatefromjpeg() function in PHP?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 3K+ Views

The imagecreatefromjpeg() function is an inbuilt PHP function that creates a new image resource from a JPEG file. It returns an image identifier representing the image obtained from the given filename. Syntax resource imagecreatefromjpeg(string $filename) Parameters $filename − The name or path to the JPEG image file to be loaded. Return Value Returns an image resource identifier on success, or false on failure. Note: This function requires the GD extension to be enabled in PHP. Example 1 − Basic Image Loading and Display The following example shows ...

Read More

PHP 8 – How to use ValueError to check if the value encountered is of correct type?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 624 Views

PHP 8 introduces a new built-in exception ValueError. PHP throws this exception when we pass a value to a function that has a valid type but cannot be used for the operation. In earlier versions of PHP, we used to get a Warning error in such cases, but PHP 8 will throw a ValueError instead. What is ValueError? ValueError is thrown when a function receives an argument of the correct type, but the value itself is inappropriate for the operation. This makes error handling more consistent and allows developers to catch these specific errors using try-catch blocks. ...

Read More

How the Non-Capturing Exception Catches work in PHP 8?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 363 Views

In PHP versions prior to 8, catching an exception required storing it in a variable, even if that variable wasn't used. PHP 8 introduced non-capturing exception catches, allowing you to catch exceptions without the mandatory variable assignment. Traditional Exception Catching (Before PHP 8) Before PHP 8, the catch block required a variable to store the exception object ? Hello World In this example, the exception is caught using the variable $e, which holds the exception object and allows access to its methods like getMessage(). Non-Capturing Exception Catches (PHP 8+) PHP 8 allows you to omit the variable when you don't need to access exception details ?

Read More

fdiv() function in PHP 8

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 458 Views

In PHP 8, the fdiv() function performs floating−point division according to the IEEE 754 standard. Unlike regular division, fdiv() allows division by zero without throwing errors, instead returning special IEEE 754 values. Syntax fdiv(float $num1, float $num2): float Parameters $num1 − The dividend (number to be divided) $num2 − The divisor (number to divide by) Return Value The function returns one of the following values ? INF (Infinity) − When a positive number is divided by zero -INF (Negative Infinity) − When a negative number is divided by ...

Read More

str_starts_with and str_ends_with function in PHP 8

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 318 Views

PHP 8 introduced two convenient string functions: str_starts_with() and str_ends_with(). These functions check if a given string starts or ends with another string, returning true if the condition is met, otherwise false. str_starts_with() Function This function checks if a string starts with a specified substring (needle). It performs a case-sensitive comparison. Syntax str_starts_with(string $haystack, string $needle): bool Example

Read More

What are Weak Maps in PHP?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 508 Views

Weak Maps in PHP are a memory-efficient data structure that creates weak references to objects, allowing automatic garbage collection when objects are no longer needed elsewhere in your code. Introduced in PHP 8.0, weak maps help prevent memory leaks by automatically removing entries when their object keys are destroyed. How Weak Maps Work A WeakMap stores key-value pairs where the keys must be objects and are weakly referenced. Unlike regular arrays or maps, if an object used as a key is destroyed (no other references exist), the corresponding entry in the WeakMap is automatically removed during garbage collection ...

Read More

What is Trailing Comma in PHP?

Urmila Samariya
Urmila Samariya
Updated on 15-Mar-2026 2K+ Views

Trailing commas in PHP allow you to add a comma after the last element in arrays, function parameters, and function calls. This feature was introduced in PHP 7.2 for arrays and expanded in PHP 8.0 for function parameters and calls. Benefits of Trailing Commas Trailing commas make code more maintainable by allowing you to add new elements without modifying existing lines. This reduces merge conflicts in version control and makes code changes cleaner. Arrays (PHP 7.2+) You can use trailing commas in arrays since PHP 7.2 − Array ( ...

Read More
Showing 10091–10100 of 21,090 articles
Advertisements