| 
version 1.1, 2012/02/21 23:48:02
 | 
version 1.1.1.4.2.1.2.1, 2014/06/15 20:15:52
 | 
| 
 Line 2
 | 
 Line 2
 | 
 |     +----------------------------------------------------------------------+ | 
     +----------------------------------------------------------------------+ | 
 |     | PHP Version 5                                                        | | 
     | PHP Version 5                                                        | | 
 |     +----------------------------------------------------------------------+ | 
     +----------------------------------------------------------------------+ | 
|    | Copyright (c) 1997-2012 The PHP Group                                | |    | Copyright (c) 1997-2013 The PHP Group                                | | 
 |     +----------------------------------------------------------------------+ | 
     +----------------------------------------------------------------------+ | 
 |     | This source file is subject to version 3.01 of the PHP license,      | | 
     | This source file is subject to version 3.01 of the PHP license,      | | 
 |     | that is bundled with this package in the file LICENSE, and is        | | 
     | that is bundled with this package in the file LICENSE, and is        | | 
| 
 Line 31
 | 
 Line 31
 | 
 |  #endif | 
  #endif | 
 |  #include "php_image.h" | 
  #include "php_image.h" | 
 |   | 
   | 
 |   | 
  #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) | 
 |  #include "zlib.h" | 
  #include "zlib.h" | 
 |   | 
  #endif | 
 |   | 
   | 
 |  /* file type markers */ | 
  /* file type markers */ | 
 |  PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'}; | 
  PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'}; | 
| 
 Line 79  PHP_MINIT_FUNCTION(imagetypes)
 | 
 Line 81  PHP_MINIT_FUNCTION(imagetypes)
 | 
 |          REGISTER_LONG_CONSTANT("IMAGETYPE_JP2",     IMAGE_FILETYPE_JP2,     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_JPX",     IMAGE_FILETYPE_JPX,     CONST_CS | CONST_PERSISTENT); | 
 |          REGISTER_LONG_CONSTANT("IMAGETYPE_JB2",     IMAGE_FILETYPE_JB2,     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); | 
          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_IFF",     IMAGE_FILETYPE_IFF,     CONST_CS | CONST_PERSISTENT); | 
 |          REGISTER_LONG_CONSTANT("IMAGETYPE_WBMP",    IMAGE_FILETYPE_WBMP,    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_JPEG2000",IMAGE_FILETYPE_JPC,     CONST_CS | CONST_PERSISTENT); /* keep alias */ | 
| 
 Line 108  static struct gfxinfo *php_handle_gif (php_stream * st
 | 
 Line 112  static struct gfxinfo *php_handle_gif (php_stream * st
 | 
 |          result->width    = (unsigned int)dim[0] | (((unsigned int)dim[1])<<8); | 
          result->width    = (unsigned int)dim[0] | (((unsigned int)dim[1])<<8); | 
 |          result->height   = (unsigned int)dim[2] | (((unsigned int)dim[3])<<8); | 
          result->height   = (unsigned int)dim[2] | (((unsigned int)dim[3])<<8); | 
 |          result->bits     = dim[4]&0x80 ? ((((unsigned int)dim[4])&0x07) + 1) : 0; | 
          result->bits     = dim[4]&0x80 ? ((((unsigned int)dim[4])&0x07) + 1) : 0; | 
|         result->channels = 3; /* allways */ |         result->channels = 3; /* always */ | 
 |   | 
   | 
 |          return result; | 
          return result; | 
 |  } | 
  } | 
| 
 Line 155  static struct gfxinfo *php_handle_bmp (php_stream * st
 | 
 Line 159  static struct gfxinfo *php_handle_bmp (php_stream * st
 | 
 |                  result->width    =  (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]); | 
                  result->width    =  (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]); | 
 |                  result->height   =  (((unsigned int)dim[ 7]) << 8) + ((unsigned int) dim[ 6]); | 
                  result->height   =  (((unsigned int)dim[ 7]) << 8) + ((unsigned int) dim[ 6]); | 
 |                  result->bits     =  ((unsigned int)dim[11]); | 
                  result->bits     =  ((unsigned int)dim[11]); | 
|         } else if (size > 12 && (size <= 64 || size == 108)) { |         } else if (size > 12 && (size <= 64 || size == 108 || size == 124)) { | 
 |                  result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo)); | 
                  result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo)); | 
 |                  result->width    =  (((unsigned int)dim[ 7]) << 24) + (((unsigned int)dim[ 6]) << 16) + (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]); | 
                  result->width    =  (((unsigned int)dim[ 7]) << 24) + (((unsigned int)dim[ 6]) << 16) + (((unsigned int)dim[ 5]) << 8) + ((unsigned int) dim[ 4]); | 
 |                  result->height   =  (((unsigned int)dim[11]) << 24) + (((unsigned int)dim[10]) << 16) + (((unsigned int)dim[ 9]) << 8) + ((unsigned int) dim[ 8]); | 
                  result->height   =  (((unsigned int)dim[11]) << 24) + (((unsigned int)dim[10]) << 16) + (((unsigned int)dim[ 9]) << 8) + ((unsigned int) dim[ 8]); | 
| 
 Line 184  static unsigned long int php_swf_get_bits (unsigned ch
 | 
 Line 188  static unsigned long int php_swf_get_bits (unsigned ch
 | 
 |  } | 
  } | 
 |  /* }}} */ | 
  /* }}} */ | 
 |   | 
   | 
 |   | 
  #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) | 
 |  /* {{{ php_handle_swc | 
  /* {{{ php_handle_swc | 
 |   */ | 
   */ | 
 |  static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) | 
  static struct gfxinfo *php_handle_swc(php_stream * stream TSRMLS_DC) | 
| 
 Line 254  static struct gfxinfo *php_handle_swc(php_stream * str
 | 
 Line 259  static struct gfxinfo *php_handle_swc(php_stream * str
 | 
 |          return result; | 
          return result; | 
 |  } | 
  } | 
 |  /* }}} */ | 
  /* }}} */ | 
 |   | 
  #endif | 
 |   | 
   | 
 |  /* {{{ php_handle_swf | 
  /* {{{ php_handle_swf | 
 |   */ | 
   */ | 
| 
 Line 600  static struct gfxinfo *php_handle_jpc(php_stream * str
 | 
 Line 606  static struct gfxinfo *php_handle_jpc(php_stream * str
 | 
 |   | 
   | 
 |          /* JPEG 2000 components can be vastly different from one another. | 
          /* JPEG 2000 components can be vastly different from one another. | 
 |             Each component can be sampled at a different resolution, use | 
             Each component can be sampled at a different resolution, use | 
|            a different colour space, have a seperate colour depth, and |            a different colour space, have a separate colour depth, and | 
 |             be compressed totally differently! This makes giving a single | 
             be compressed totally differently! This makes giving a single | 
 |             "bit depth" answer somewhat problematic. For this implementation | 
             "bit depth" answer somewhat problematic. For this implementation | 
 |             we'll use the highest depth encountered. */ | 
             we'll use the highest depth encountered. */ | 
| 
 Line 1283  PHPAPI int php_getimagetype(php_stream * stream, char 
 | 
 Line 1289  PHPAPI int php_getimagetype(php_stream * stream, char 
 | 
 |  } | 
  } | 
 |  /* }}} */ | 
  /* }}} */ | 
 |   | 
   | 
| /* {{{ proto array getimagesize(string imagefile [, array info]) | static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ | 
|    Get the size of an image as 4-element array */ |   | 
| PHP_FUNCTION(getimagesize) |   | 
 |  { | 
  { | 
|         zval **info = NULL; |         char *temp; | 
|         char *arg1, *temp; |         int itype = 0; | 
|         int arg1_len, itype = 0, argc = ZEND_NUM_ARGS(); |   | 
 |          struct gfxinfo *result = NULL; | 
          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) { | 
          if (!stream) { | 
 |                  RETURN_FALSE; | 
                  RETURN_FALSE; | 
 |          } | 
          } | 
| 
 Line 1327  PHP_FUNCTION(getimagesize)
 | 
 Line 1318  PHP_FUNCTION(getimagesize)
 | 
 |                          result = php_handle_swf(stream TSRMLS_CC); | 
                          result = php_handle_swf(stream TSRMLS_CC); | 
 |                          break; | 
                          break; | 
 |                  case IMAGE_FILETYPE_SWC: | 
                  case IMAGE_FILETYPE_SWC: | 
 |   | 
  #if HAVE_ZLIB && !defined(COMPILE_DL_ZLIB) | 
 |                          result = php_handle_swc(stream TSRMLS_CC); | 
                          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; | 
                          break; | 
 |                  case IMAGE_FILETYPE_PSD: | 
                  case IMAGE_FILETYPE_PSD: | 
 |                          result = php_handle_psd(stream TSRMLS_CC); | 
                          result = php_handle_psd(stream TSRMLS_CC); | 
| 
 Line 1364  PHP_FUNCTION(getimagesize)
 | 
 Line 1359  PHP_FUNCTION(getimagesize)
 | 
 |                          break; | 
                          break; | 
 |          } | 
          } | 
 |   | 
   | 
 |          php_stream_close(stream); | 
   | 
 |   | 
   | 
 |          if (result) { | 
          if (result) { | 
 |                  array_init(return_value); | 
                  array_init(return_value); | 
 |                  add_index_long(return_value, 0, result->width); | 
                  add_index_long(return_value, 0, result->width); | 
| 
 Line 1387  PHP_FUNCTION(getimagesize)
 | 
 Line 1380  PHP_FUNCTION(getimagesize)
 | 
 |          } | 
          } | 
 |  } | 
  } | 
 |  /* }}} */ | 
  /* }}} */ | 
 |   | 
   | 
 |   | 
  #define FROM_DATA 0 | 
 |   | 
  #define FROM_PATH 1 | 
 |   | 
   | 
 |   | 
  static void php_getimagesize_from_any(INTERNAL_FUNCTION_PARAMETERS, int mode) {  /* {{{ */ | 
 |   | 
          zval **info = NULL; | 
 |   | 
          php_stream *stream = NULL; | 
 |   | 
          char *input; | 
 |   | 
          int input_len; | 
 |   | 
          const int argc = ZEND_NUM_ARGS(); | 
 |   | 
   | 
 |   | 
          if (zend_parse_parameters(argc TSRMLS_CC, "s|Z", &input, &input_len, &info) == FAILURE) { | 
 |   | 
                          return; | 
 |   | 
          } | 
 |   | 
   | 
 |   | 
          if (argc == 2) { | 
 |   | 
                          zval_dtor(*info); | 
 |   | 
                          array_init(*info); | 
 |   | 
          } | 
 |   | 
   | 
 |   | 
   | 
 |   | 
          if (mode == FROM_PATH) { | 
 |   | 
                  stream = php_stream_open_wrapper(input, "rb", STREAM_MUST_SEEK|REPORT_ERRORS|IGNORE_PATH, NULL); | 
 |   | 
          } else { | 
 |   | 
                  stream = php_stream_memory_open(TEMP_STREAM_READONLY, input, input_len); | 
 |   | 
          } | 
 |   | 
   | 
 |   | 
          if (!stream) { | 
 |   | 
                     RETURN_FALSE; | 
 |   | 
          } | 
 |   | 
   | 
 |   | 
          php_getimagesize_from_stream(stream, info, INTERNAL_FUNCTION_PARAM_PASSTHRU); | 
 |   | 
          php_stream_close(stream); | 
 |   | 
  } | 
 |   | 
  /* }}} */ | 
 |   | 
   | 
 |   | 
  /* {{{ proto array getimagesize(string imagefile [, array info]) | 
 |   | 
     Get the size of an image as 4-element array */ | 
 |   | 
  PHP_FUNCTION(getimagesize) | 
 |   | 
  { | 
 |   | 
          php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_PATH); | 
 |   | 
  } | 
 |   | 
  /* }}} */ | 
 |   | 
   | 
 |   | 
  /* {{{ proto array getimagesizefromstring(string data [, array info]) | 
 |   | 
     Get the size of an image as 4-element array */ | 
 |   | 
  PHP_FUNCTION(getimagesizefromstring) | 
 |   | 
  { | 
 |   | 
          php_getimagesize_from_any(INTERNAL_FUNCTION_PARAM_PASSTHRU, FROM_DATA); | 
 |   | 
  } | 
 |   | 
   | 
 |  /* | 
  /* | 
 |   * Local variables: | 
   * Local variables: |