Back to index

php5  5.3.10
Enumerations | Functions
php_image.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Enumerations

enum  image_filetype {
  IMAGE_FILETYPE_UNKNOWN = 0, IMAGE_FILETYPE_GIF = 1, IMAGE_FILETYPE_JPEG, IMAGE_FILETYPE_PNG,
  IMAGE_FILETYPE_SWF, IMAGE_FILETYPE_PSD, IMAGE_FILETYPE_BMP, IMAGE_FILETYPE_TIFF_II,
  IMAGE_FILETYPE_TIFF_MM, IMAGE_FILETYPE_JPC, IMAGE_FILETYPE_JP2, IMAGE_FILETYPE_JPX,
  IMAGE_FILETYPE_JB2, IMAGE_FILETYPE_SWC, IMAGE_FILETYPE_IFF, IMAGE_FILETYPE_WBMP,
  IMAGE_FILETYPE_XBM, IMAGE_FILETYPE_ICO, IMAGE_FILETYPE_COUNT
}

Functions

 PHP_FUNCTION (getimagesize)
 PHP_FUNCTION (image_type_to_mime_type)
 PHP_FUNCTION (image_type_to_extension)
 PHP_MINIT_FUNCTION (imagetypes)
PHPAPI int php_getimagetype (php_stream *stream, char *filetype TSRMLS_DC)
PHPAPI char * php_image_type_to_mime_type (int image_type)

Enumeration Type Documentation

Enumerator:
IMAGE_FILETYPE_UNKNOWN 
IMAGE_FILETYPE_GIF 
IMAGE_FILETYPE_JPEG 
IMAGE_FILETYPE_PNG 
IMAGE_FILETYPE_SWF 
IMAGE_FILETYPE_PSD 
IMAGE_FILETYPE_BMP 
IMAGE_FILETYPE_TIFF_II 
IMAGE_FILETYPE_TIFF_MM 
IMAGE_FILETYPE_JPC 
IMAGE_FILETYPE_JP2 
IMAGE_FILETYPE_JPX 
IMAGE_FILETYPE_JB2 
IMAGE_FILETYPE_SWC 
IMAGE_FILETYPE_IFF 
IMAGE_FILETYPE_WBMP 
IMAGE_FILETYPE_XBM 
IMAGE_FILETYPE_ICO 
IMAGE_FILETYPE_COUNT 

Definition at line 34 of file php_image.h.


Function Documentation

PHP_FUNCTION ( getimagesize  )

Definition at line 1294 of file image.c.

{
       zval **info = NULL;
       char *arg1, *temp;
       int arg1_len, itype = 0, argc = ZEND_NUM_ARGS();
       struct gfxinfo *result = NULL;
       php_stream * stream = NULL;

       if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &arg1, &arg1_len, &info) == FAILURE) {
              return;
       }
       
       if (argc == 2) {
              zval_dtor(*info);
              array_init(*info);
       }

       stream = php_stream_open_wrapper(arg1, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH|ENFORCE_SAFE_MODE, NULL);

       if (!stream) {
              RETURN_FALSE;
       }

       itype = php_getimagetype(stream, NULL TSRMLS_CC);
       switch( itype) {
              case IMAGE_FILETYPE_GIF:
                     result = php_handle_gif(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JPEG:
                     if (info) {
                            result = php_handle_jpeg(stream, *info TSRMLS_CC);
                     } else {
                            result = php_handle_jpeg(stream, NULL TSRMLS_CC);
                     }
                     break;
              case IMAGE_FILETYPE_PNG:
                     result = php_handle_png(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_SWF:
                     result = php_handle_swf(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_SWC:
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
                     result = php_handle_swc(stream TSRMLS_CC);
#else
                     php_error_docref(NULL TSRMLS_CC, E_NOTICE, "The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled");
#endif
                     break;
              case IMAGE_FILETYPE_PSD:
                     result = php_handle_psd(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_BMP:
                     result = php_handle_bmp(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_TIFF_II:
                     result = php_handle_tiff(stream, NULL, 0 TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_TIFF_MM:
                     result = php_handle_tiff(stream, NULL, 1 TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JPC:
                     result = php_handle_jpc(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_JP2:
                     result = php_handle_jp2(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_IFF:
                     result = php_handle_iff(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_WBMP:
                     result = php_handle_wbmp(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_XBM:
                     result = php_handle_xbm(stream TSRMLS_CC);
                     break;
              case IMAGE_FILETYPE_ICO:
                     result = php_handle_ico(stream TSRMLS_CC);
                     break;
              default:
              case IMAGE_FILETYPE_UNKNOWN:
                     break;
       }

       php_stream_close(stream);

       if (result) {
              array_init(return_value);
              add_index_long(return_value, 0, result->width);
              add_index_long(return_value, 1, result->height);
              add_index_long(return_value, 2, itype);
              spprintf(&temp, 0, "width=\"%d\" height=\"%d\"", result->width, result->height);
              add_index_string(return_value, 3, temp, 0);

              if (result->bits != 0) {
                     add_assoc_long(return_value, "bits", result->bits);
              }
              if (result->channels != 0) {
                     add_assoc_long(return_value, "channels", result->channels);
              }
              add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1);
              efree(result);
       } else {
              RETURN_FALSE;
       }
}

Here is the call graph for this function:

PHP_FUNCTION ( image_type_to_mime_type  )

Definition at line 1156 of file image.c.

{
       long p_image_type;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &p_image_type) == FAILURE) {
              return;
       }

       ZVAL_STRING(return_value, (char*)php_image_type_to_mime_type(p_image_type), 1);
}

Here is the call graph for this function:

PHP_FUNCTION ( image_type_to_extension  )

Definition at line 1170 of file image.c.

{
       long image_type;
       zend_bool inc_dot=1;

       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l|b", &image_type, &inc_dot) == FAILURE) {
              RETURN_FALSE;
       }

       switch (image_type) {
              case IMAGE_FILETYPE_GIF:
                     RETURN_STRING(".gif" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPEG:
                     RETURN_STRING(".jpeg" + !inc_dot, 1);
              case IMAGE_FILETYPE_PNG:
                     RETURN_STRING(".png" + !inc_dot, 1);
              case IMAGE_FILETYPE_SWF:
              case IMAGE_FILETYPE_SWC:
                     RETURN_STRING(".swf" + !inc_dot, 1);
              case IMAGE_FILETYPE_PSD:
                     RETURN_STRING(".psd" + !inc_dot, 1);
              case IMAGE_FILETYPE_BMP:
              case IMAGE_FILETYPE_WBMP:
                     RETURN_STRING(".bmp" + !inc_dot, 1);
              case IMAGE_FILETYPE_TIFF_II:
              case IMAGE_FILETYPE_TIFF_MM:
                     RETURN_STRING(".tiff" + !inc_dot, 1);
              case IMAGE_FILETYPE_IFF:
                     RETURN_STRING(".iff" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPC:
                     RETURN_STRING(".jpc" + !inc_dot, 1);
              case IMAGE_FILETYPE_JP2:
                     RETURN_STRING(".jp2" + !inc_dot, 1);
              case IMAGE_FILETYPE_JPX:
                     RETURN_STRING(".jpx" + !inc_dot, 1);
              case IMAGE_FILETYPE_JB2:
                     RETURN_STRING(".jb2" + !inc_dot, 1);
              case IMAGE_FILETYPE_XBM:
                     RETURN_STRING(".xbm" + !inc_dot, 1);
              case IMAGE_FILETYPE_ICO:
                     RETURN_STRING(".ico" + !inc_dot, 1);
       }

       RETURN_FALSE;
}

Here is the call graph for this function:

PHPAPI int php_getimagetype ( php_stream *  stream,
char *filetype  TSRMLS_DC 
)

Definition at line 1219 of file image.c.

{
       char tmp[12];

       if ( !filetype) filetype = tmp;
       if((php_stream_read(stream, filetype, 3)) != 3) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }

/* BYTES READ: 3 */
       if (!memcmp(filetype, php_sig_gif, 3)) {
              return IMAGE_FILETYPE_GIF;
       } else if (!memcmp(filetype, php_sig_jpg, 3)) {
              return IMAGE_FILETYPE_JPEG;
       } else if (!memcmp(filetype, php_sig_png, 3)) {
              if (php_stream_read(stream, filetype+3, 5) != 5) {
                     php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
                     return IMAGE_FILETYPE_UNKNOWN;
              }
              if (!memcmp(filetype, php_sig_png, 8)) {
                     return IMAGE_FILETYPE_PNG;
              } else {
                     php_error_docref(NULL TSRMLS_CC, E_WARNING, "PNG file corrupted by ASCII conversion");
                     return IMAGE_FILETYPE_UNKNOWN;
              }
       } else if (!memcmp(filetype, php_sig_swf, 3)) {
              return IMAGE_FILETYPE_SWF;
       } else if (!memcmp(filetype, php_sig_swc, 3)) {
              return IMAGE_FILETYPE_SWC;
       } else if (!memcmp(filetype, php_sig_psd, 3)) {
              return IMAGE_FILETYPE_PSD;
       } else if (!memcmp(filetype, php_sig_bmp, 2)) {
              return IMAGE_FILETYPE_BMP;
       } else if (!memcmp(filetype, php_sig_jpc, 3)) {
              return IMAGE_FILETYPE_JPC;
       }

       if (php_stream_read(stream, filetype+3, 1) != 1) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }
/* BYTES READ: 4 */
       if (!memcmp(filetype, php_sig_tif_ii, 4)) {
              return IMAGE_FILETYPE_TIFF_II;
       } else if (!memcmp(filetype, php_sig_tif_mm, 4)) {
              return IMAGE_FILETYPE_TIFF_MM;
       } else if (!memcmp(filetype, php_sig_iff, 4)) {
              return IMAGE_FILETYPE_IFF;
       } else if (!memcmp(filetype, php_sig_ico, 4)) {
              return IMAGE_FILETYPE_ICO;
       }

       if (php_stream_read(stream, filetype+4, 8) != 8) {
              php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Read error!");
              return IMAGE_FILETYPE_UNKNOWN;
       }
/* BYTES READ: 12 */
       if (!memcmp(filetype, php_sig_jp2, 12)) {
              return IMAGE_FILETYPE_JP2;
       }

/* AFTER ALL ABOVE FAILED */
       if (php_get_wbmp(stream, NULL, 1 TSRMLS_CC)) {
              return IMAGE_FILETYPE_WBMP;
       }
       if (php_get_xbm(stream, NULL TSRMLS_CC)) {
              return IMAGE_FILETYPE_XBM;
       }
       return IMAGE_FILETYPE_UNKNOWN;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PHPAPI char* php_image_type_to_mime_type ( int  image_type)

Definition at line 1116 of file image.c.

{
       switch( image_type) {
              case IMAGE_FILETYPE_GIF:
                     return "image/gif";
              case IMAGE_FILETYPE_JPEG:
                     return "image/jpeg";
              case IMAGE_FILETYPE_PNG:
                     return "image/png";
              case IMAGE_FILETYPE_SWF:
              case IMAGE_FILETYPE_SWC:
                     return "application/x-shockwave-flash";
              case IMAGE_FILETYPE_PSD:
                     return "image/psd";
              case IMAGE_FILETYPE_BMP:
                     return "image/x-ms-bmp";
              case IMAGE_FILETYPE_TIFF_II:
              case IMAGE_FILETYPE_TIFF_MM:
                     return "image/tiff";
              case IMAGE_FILETYPE_IFF:
                     return "image/iff";
              case IMAGE_FILETYPE_WBMP:
                     return "image/vnd.wap.wbmp";
              case IMAGE_FILETYPE_JPC:
                     return "application/octet-stream";
              case IMAGE_FILETYPE_JP2:
                     return "image/jp2";
              case IMAGE_FILETYPE_XBM:
                     return "image/xbm";
              case IMAGE_FILETYPE_ICO:
                     return "image/vnd.microsoft.icon";
              default:
              case IMAGE_FILETYPE_UNKNOWN:
                     return "application/octet-stream"; /* suppose binary format */
       }
}

Here is the caller graph for this function:

PHP_MINIT_FUNCTION ( imagetypes  )

Definition at line 70 of file image.c.

{
       REGISTER_LONG_CONSTANT("IMAGETYPE_GIF",     IMAGE_FILETYPE_GIF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG",    IMAGE_FILETYPE_JPEG,    CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_PNG",     IMAGE_FILETYPE_PNG,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_SWF",     IMAGE_FILETYPE_SWF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_PSD",     IMAGE_FILETYPE_PSD,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_BMP",     IMAGE_FILETYPE_BMP,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_II", IMAGE_FILETYPE_TIFF_II, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_TIFF_MM", IMAGE_FILETYPE_TIFF_MM, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPC",     IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JP2",     IMAGE_FILETYPE_JP2,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPX",     IMAGE_FILETYPE_JPX,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JB2",     IMAGE_FILETYPE_JB2,     CONST_CS | CONST_PERSISTENT);
#if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB)
       REGISTER_LONG_CONSTANT("IMAGETYPE_SWC",     IMAGE_FILETYPE_SWC,     CONST_CS | CONST_PERSISTENT);
#endif 
       REGISTER_LONG_CONSTANT("IMAGETYPE_IFF",     IMAGE_FILETYPE_IFF,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP",    IMAGE_FILETYPE_WBMP,    CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_JPEG2000",IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT); /* keep alias */
       REGISTER_LONG_CONSTANT("IMAGETYPE_XBM",     IMAGE_FILETYPE_XBM,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_ICO",     IMAGE_FILETYPE_ICO,     CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_CS | CONST_PERSISTENT);
       REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT",   IMAGE_FILETYPE_COUNT,   CONST_CS | CONST_PERSISTENT);
       return SUCCESS;
}