Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
imagesy() function in PHP
The imagesy() function gets the height of an image resource in PHP. It returns the height of the image in pixels or FALSE on errors.
Syntax
imagesy(image)
Parameters
image − An image resource created by one of the image creation functions like
imagecreatetruecolor(),imagecreatefromjpeg(), etc.
Return Value
The imagesy() function returns the height of the image in pixels as an integer, or FALSE on failure.
Example
The following example demonstrates how to get the height of a newly created image −
<?php
$img = imagecreatetruecolor(450, 250);
echo "Image height: " . imagesy($img) . " pixels";
?>
The output of the above code is −
Image height: 250 pixels
Using with Existing Images
You can also use imagesy() with images loaded from files −
<?php
// Load an existing image (requires file system access)
$img = imagecreatefromjpeg('sample.jpg');
if ($img !== false) {
$height = imagesy($img);
echo "Image height: " . $height . " pixels";
imagedestroy($img);
} else {
echo "Failed to load image";
}
?>
Conclusion
The imagesy() function is essential for determining image dimensions in PHP image processing. Always check if the image resource is valid before using this function to avoid errors.
