PHP Articles

Page 21 of 81

How to draw a partial arc and fill it using imagefilledarc() function in PHP?

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

The imagefilledarc() function is a built-in PHP function used to draw and fill a partial arc. This function requires the GD extension and is commonly used for creating pie charts, progress indicators, and other graphical elements. Note: To use imagefilledarc(), you need the GD extension enabled in PHP. Install it using: sudo apt-get install php-gd on Ubuntu/Debian or enable it in php.ini on Windows. Syntax bool imagefilledarc($image, $cx, $cy, $width, $height, $start, $end, $color, $style) Parameters The imagefilledarc() function takes nine parameters − $image − Image resource created by ...

Read More

How to draw an ellipse using imageellipse() function in PHP?

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

The imageellipse() function is an inbuilt PHP function used to draw an ellipse on an image resource. It returns True on success and False on failure. Syntax bool imageellipse($image, $cx, $cy, $width, $height, $color) Parameters The imageellipse() function takes six parameters − $image − An image resource created by functions like imagecreatetruecolor(). $cx − The x-coordinate of the ellipse center. $cy − The y-coordinate of the ellipse center. $width − The width of the ellipse. $height − The height of the ellipse. $color − The color identifier created by imagecolorallocate() function. ...

Read More

How to create a new true-color image in PHP using imagecreatetruecolor()?

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

The imagecreatetruecolor() function is an inbuilt function in PHP that creates a new true-color image resource. It returns a blank image canvas of the specified dimensions that can be used for drawing operations. Syntax resource imagecreatetruecolor($width, $height) Parameters The imagecreatetruecolor() function takes two parameters: $width − The width of the image in pixels. $height − The height of the image in pixels. Return Value Returns an image resource identifier on success, or FALSE on errors. Example 1 − Creating a Polygon Image This example creates a true-color ...

Read More

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 736 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 610 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 352 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 447 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
Showing 201–210 of 802 articles
« Prev 1 19 20 21 22 23 81 Next »
Advertisements