PHP Get Image Width and Height

PHP 图像处理PHP Image Processing

PHP Get Image Width Function: imagesx()

The imagesx() function is used to get the width of an image, in pixels, and returns an integer.

Syntax:

int imagesx( resource image )

The image parameter is an image resource returned by functions such as imagecreatetruecolor(), imagecreatefromjpeg(), etc.

PHP Get Image Height Function: imagesy()

The imagesy() function is used to get the height of an image. Its syntax and usage are the same as imagesx().

Syntax:

int imagesy( resource image )

The image parameter is an image resource returned by functions such as imagecreatetruecolor(), imagecreatefromjpeg(), etc.

Example

<?php
$img = imagecreatefrompng("example-logo.png");
echo "图像宽度:",imagesx( $img ),"<br />";
echo "图像高度:",imagesy( $img );
?>

Browser output:

图像宽度:290
图像高度:69

Related Articles

Functions for getting image information:getimagesize()

PHP 图像处理PHP Image Processing

Other Extensions