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.

Updated on: 2026-03-15T07:48:23+05:30

142 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements