Name

getimagesize

Synopsis

array getimagesize(string path[, array &info])

Returns an array with five elements by checking the size of the image found at path. Path can either be absolute path to a file on the filesystem, or a URI pointing to a file. The following elements are returned in the array:

0

The width of the image in pixels

1

The height of the image in pixels

2

The type of the image according to the values in the next table

3

The height and width as a string that can be used inside an IMG element directly (for example, height="123” width="16”)

mime

The MIME type for the image

channels

If it can be determined, the number of channels in the image (for example, 3 for RGB images or 4 for CMYK images)

bits

If it can be determined, the number of bits used for each pixel in the image

The image types supported and the type value and MIME type returned for each image type are as follows:

1

Graphics Interchange Format (GIF)

2

JPEG

3

Portable Network Graphics format (PNG)

4

Shockwave or Flash animation (SWF)

5

PhotoShop file (PSD)

6

Windows bitmap format (BMP)

7

TIFF (Intel byte-ordered)

8

TIFF (Motorola byte-ordered)

9

JPC

10

JP2

11

JPX

12

JB2

13

SWC

14

IFF

15

WBMP

16

XBM

If supplied, the array info is filled with additional information parsed from the file, depending on the file type. For example, JPEG files may contain IPTC data in JPG APP markers. In cases where they exist, marker keys and values are returned in info.

Get Programming PHP, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.