@@ -4305,33 +4305,35 @@ static int exif_discard_imageinfo(image_info_type *ImageInfo)
4305
4305
}
4306
4306
/* }}} */
4307
4307
4308
- /* {{{ exif_read_file
4308
+ /* {{{ exif_read_from_stream
4309
4309
*/
4310
- static int exif_read_file (image_info_type * ImageInfo , char * FileName , int read_thumbnail , int read_all )
4310
+ static int exif_read_from_stream (image_info_type * ImageInfo , php_stream * stream , int read_thumbnail , int read_all )
4311
4311
{
4312
4312
int ret ;
4313
4313
zend_stat_t st ;
4314
- zend_string * base ;
4315
4314
4316
4315
/* Start with an empty image information structure. */
4317
4316
memset (ImageInfo , 0 , sizeof (* ImageInfo ));
4318
4317
4319
- ImageInfo -> motorola_intel = -1 ; /* flag as unknown */
4320
-
4321
- ImageInfo -> infile = php_stream_open_wrapper (FileName , "rb" , STREAM_MUST_SEEK |IGNORE_PATH , NULL );
4322
- if (!ImageInfo -> infile ) {
4323
- exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_WARNING , "Unable to open file ");
4324
- return FALSE;
4325
- }
4318
+ ImageInfo -> motorola_intel = -1 ; /* flag as unknown */
4319
+ ImageInfo -> infile = stream ;
4320
+ ImageInfo -> FileName = NULL ;
4326
4321
4327
4322
if (php_stream_is (ImageInfo -> infile , PHP_STREAM_IS_STDIO )) {
4328
- if (VCWD_STAT (FileName , & st ) >= 0 ) {
4323
+ if (VCWD_STAT (stream -> orig_path , & st ) >= 0 ) {
4324
+ zend_string * base ;
4329
4325
if ((st .st_mode & S_IFMT ) != S_IFREG ) {
4330
4326
exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_WARNING , "Not a file ");
4331
4327
php_stream_close (ImageInfo -> infile );
4332
4328
return FALSE;
4333
4329
}
4334
4330
4331
+ /* Store file name */
4332
+ base = php_basename (stream -> orig_path , strlen (stream -> orig_path ), NULL , 0 );
4333
+ ImageInfo -> FileName = estrndup (ZSTR_VAL (base ), ZSTR_LEN (base ));
4334
+
4335
+ zend_string_release (base );
4336
+
4335
4337
/* Store file date/time. */
4336
4338
ImageInfo -> FileDateTime = st .st_mtime ;
4337
4339
ImageInfo -> FileSize = st .st_size ;
@@ -4345,51 +4347,76 @@ static int exif_read_file(image_info_type *ImageInfo, char *FileName, int read_t
4345
4347
}
4346
4348
}
4347
4349
4348
- base = php_basename (FileName , strlen (FileName ), NULL , 0 );
4349
- ImageInfo -> FileName = estrndup (ZSTR_VAL (base ), ZSTR_LEN (base ));
4350
- zend_string_release (base );
4351
- ImageInfo -> read_thumbnail = read_thumbnail ;
4352
- ImageInfo -> read_all = read_all ;
4353
- ImageInfo -> Thumbnail .filetype = IMAGE_FILETYPE_UNKNOWN ;
4350
+ ImageInfo -> read_thumbnail = read_thumbnail ;
4351
+ ImageInfo -> read_all = read_all ;
4352
+ ImageInfo -> Thumbnail .filetype = IMAGE_FILETYPE_UNKNOWN ;
4354
4353
4355
- ImageInfo -> encode_unicode = estrdup (EXIF_G (encode_unicode ));
4356
- ImageInfo -> decode_unicode_be = estrdup (EXIF_G (decode_unicode_be ));
4357
- ImageInfo -> decode_unicode_le = estrdup (EXIF_G (decode_unicode_le ));
4358
- ImageInfo -> encode_jis = estrdup (EXIF_G (encode_jis ));
4359
- ImageInfo -> decode_jis_be = estrdup (EXIF_G (decode_jis_be ));
4360
- ImageInfo -> decode_jis_le = estrdup (EXIF_G (decode_jis_le ));
4354
+ ImageInfo -> encode_unicode = estrdup (EXIF_G (encode_unicode ));
4355
+ ImageInfo -> decode_unicode_be = estrdup (EXIF_G (decode_unicode_be ));
4356
+ ImageInfo -> decode_unicode_le = estrdup (EXIF_G (decode_unicode_le ));
4357
+ ImageInfo -> encode_jis = estrdup (EXIF_G (encode_jis ));
4358
+ ImageInfo -> decode_jis_be = estrdup (EXIF_G (decode_jis_be ));
4359
+ ImageInfo -> decode_jis_le = estrdup (EXIF_G (decode_jis_le ));
4361
4360
4362
4361
4363
4362
ImageInfo -> ifd_nesting_level = 0 ;
4364
4363
4365
- /* Scan the JPEG headers. */
4364
+ /* Scan the headers */
4366
4365
ret = exif_scan_FILE_header (ImageInfo );
4367
4366
4368
- php_stream_close (ImageInfo -> infile );
4369
4367
return ret ;
4370
4368
}
4371
4369
/* }}} */
4372
4370
4373
- /* {{{ proto array exif_read_data(string filename [, string sections_needed [, bool sub_arrays[, bool read_thumbnail]]])
4374
- Reads header data from the JPEG/TIFF image filename and optionally reads the internal thumbnails */
4375
- PHP_FUNCTION ( exif_read_data )
4371
+ /* {{{ exif_read_from_file
4372
+ */
4373
+ static int exif_read_from_file ( image_info_type * ImageInfo , char * FileName , int read_thumbnail , int read_all )
4376
4374
{
4377
- char * p_name , * p_sections_needed = NULL ;
4378
- size_t p_name_len , p_sections_needed_len = 0 ;
4379
- zend_bool sub_arrays = 0 , read_thumbnail = 0 , read_all = 0 ;
4375
+ int ret ;
4376
+ php_stream * stream ;
4377
+
4378
+ stream = php_stream_open_wrapper (FileName , "rb" , STREAM_MUST_SEEK | IGNORE_PATH , NULL );
4379
+
4380
+ if (!stream ) {
4381
+ memset (& ImageInfo , 0 , sizeof (ImageInfo ));
4382
+
4383
+ exif_error_docref (NULL EXIFERR_CC , ImageInfo , E_WARNING , "Unable to open file ");
4384
+
4385
+ return FALSE;
4386
+ }
4387
+
4388
+ ret = exif_read_from_stream (ImageInfo , stream , read_thumbnail , read_all );
4389
+
4390
+ php_stream_close (stream );
4391
+
4392
+ return ret ;
4393
+ }
4394
+ /* }}} */
4380
4395
4381
- int i , ret , sections_needed = 0 ;
4396
+ /* {{{ proto array exif_read_data(mixed stream [, string sections_needed [, bool sub_arrays[, bool read_thumbnail]]])
4397
+ Reads header data from an image and optionally reads the internal thumbnails */
4398
+ PHP_FUNCTION (exif_read_data )
4399
+ {
4400
+ zend_string * z_sections_needed = NULL ;
4401
+ zend_bool sub_arrays = 0 , read_thumbnail = 0 , read_all = 0 ;
4402
+ zval * stream ;
4403
+ int i , ret , sections_needed = 0 ;
4382
4404
image_info_type ImageInfo ;
4383
4405
char tmp [64 ], * sections_str , * s ;
4384
4406
4385
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "p|sbb" , & p_name , & p_name_len , & p_sections_needed , & p_sections_needed_len , & sub_arrays , & read_thumbnail ) == FAILURE ) {
4386
- return ;
4387
- }
4407
+ /* Parse arguments */
4408
+ ZEND_PARSE_PARAMETERS_START (1 , 4 )
4409
+ Z_PARAM_ZVAL (stream )
4410
+ Z_PARAM_OPTIONAL
4411
+ Z_PARAM_STR (z_sections_needed )
4412
+ Z_PARAM_BOOL (sub_arrays )
4413
+ Z_PARAM_BOOL (read_thumbnail )
4414
+ ZEND_PARSE_PARAMETERS_END ();
4388
4415
4389
4416
memset (& ImageInfo , 0 , sizeof (ImageInfo ));
4390
4417
4391
- if (p_sections_needed ) {
4392
- spprintf (& sections_str , 0 , ",%s," , p_sections_needed );
4418
+ if (z_sections_needed ) {
4419
+ spprintf (& sections_str , 0 , ",%s ,", ZSTR_VAL ( z_sections_needed ) );
4393
4420
/* sections_str DOES start with , and SPACES are NOT allowed in names */
4394
4421
s = sections_str ;
4395
4422
while (* ++ s ) {
@@ -4409,19 +4436,39 @@ PHP_FUNCTION(exif_read_data)
4409
4436
#ifdef EXIF_DEBUG
4410
4437
sections_str = exif_get_sectionlist (sections_needed );
4411
4438
if (!sections_str ) {
4439
+ zend_string_release (z_sections_needed );
4412
4440
RETURN_FALSE ;
4413
4441
}
4414
4442
exif_error_docref (NULL EXIFERR_CC , & ImageInfo , E_NOTICE , "Sections needed: %s" , sections_str [0 ] ? sections_str : "None" );
4415
4443
EFREE_IF (sections_str );
4416
4444
#endif
4445
+ zend_string_release (z_sections_needed );
4446
+ }
4447
+
4448
+ if (Z_TYPE_P (stream ) == IS_RESOURCE ) {
4449
+ php_stream * p_stream = NULL ;
4450
+
4451
+ php_stream_from_res (p_stream , Z_RES_P (stream ));
4452
+
4453
+ ret = exif_read_from_stream (& ImageInfo , p_stream , read_thumbnail , read_all );
4454
+ } else {
4455
+ convert_to_string (stream );
4456
+
4457
+ if (!Z_STRLEN_P (stream )) {
4458
+ exif_error_docref (NULL EXIFERR_CC , & ImageInfo , E_WARNING , "Filename cannot be empty ");
4459
+
4460
+ RETURN_FALSE ;
4461
+ }
4462
+
4463
+ ret = exif_read_from_file (& ImageInfo , Z_STRVAL_P (stream ), read_thumbnail , read_all );
4417
4464
}
4418
4465
4419
- ret = exif_read_file (& ImageInfo , p_name , read_thumbnail , read_all );
4420
4466
sections_str = exif_get_sectionlist (ImageInfo .sections_found );
4421
4467
4422
4468
#ifdef EXIF_DEBUG
4423
- if (sections_str )
4469
+ if (sections_str ) {
4424
4470
exif_error_docref (NULL EXIFERR_CC , & ImageInfo , E_NOTICE , "Sections found: %s" , sections_str [0 ] ? sections_str : "None" );
4471
+ }
4425
4472
#endif
4426
4473
4427
4474
ImageInfo .sections_found |= FOUND_COMPUTED |FOUND_FILE ;/* do not inform about in debug*/
@@ -4552,24 +4599,41 @@ PHP_FUNCTION(exif_read_data)
4552
4599
Reads the embedded thumbnail */
4553
4600
PHP_FUNCTION (exif_thumbnail )
4554
4601
{
4555
- zval * p_width = 0 , * p_height = 0 , * p_imagetype = 0 ;
4556
- char * p_name ;
4557
- size_t p_name_len ;
4558
4602
int ret , arg_c = ZEND_NUM_ARGS ();
4559
4603
image_info_type ImageInfo ;
4604
+ zval * stream ;
4605
+ zval * z_width = NULL , * z_height = NULL , * z_imagetype = NULL ;
4606
+
4607
+ /* Parse arguments */
4608
+ ZEND_PARSE_PARAMETERS_START (1 , 4 )
4609
+ Z_PARAM_ZVAL (stream )
4610
+ Z_PARAM_OPTIONAL
4611
+ Z_PARAM_ZVAL_DEREF (z_width )
4612
+ Z_PARAM_ZVAL_DEREF (z_height )
4613
+ Z_PARAM_ZVAL_DEREF (z_imagetype )
4614
+ ZEND_PARSE_PARAMETERS_END ();
4560
4615
4561
4616
memset (& ImageInfo , 0 , sizeof (ImageInfo ));
4562
4617
4563
- if (arg_c != 1 && arg_c != 3 && arg_c != 4 ) {
4564
- WRONG_PARAM_COUNT ;
4565
- }
4618
+ if (Z_TYPE_P (stream ) == IS_RESOURCE ) {
4619
+ php_stream * p_stream = NULL ;
4566
4620
4567
- if (zend_parse_parameters (arg_c , "p|z/z/z/" , & p_name , & p_name_len , & p_width , & p_height , & p_imagetype ) == FAILURE ) {
4568
- return ;
4621
+ php_stream_from_res (p_stream , Z_RES_P (stream ));
4622
+
4623
+ ret = exif_read_from_stream (& ImageInfo , p_stream , 1 , 0 );
4624
+ } else {
4625
+ convert_to_string (stream );
4626
+
4627
+ if (!Z_STRLEN_P (stream )) {
4628
+ exif_error_docref (NULL EXIFERR_CC , & ImageInfo , E_WARNING , "Filename cannot be empty ");
4629
+
4630
+ RETURN_FALSE ;
4631
+ }
4632
+
4633
+ ret = exif_read_from_file (& ImageInfo , Z_STRVAL_P (stream ), 1 , 0 );
4569
4634
}
4570
4635
4571
- ret = exif_read_file (& ImageInfo , p_name , 1 , 0 );
4572
- if (ret == FALSE) {
4636
+ if (ret == FALSE) {
4573
4637
exif_discard_imageinfo (& ImageInfo );
4574
4638
RETURN_FALSE ;
4575
4639
}
@@ -4591,14 +4655,14 @@ PHP_FUNCTION(exif_thumbnail)
4591
4655
if (!ImageInfo .Thumbnail .width || !ImageInfo .Thumbnail .height ) {
4592
4656
exif_scan_thumbnail (& ImageInfo );
4593
4657
}
4594
- zval_dtor (p_width );
4595
- zval_dtor (p_height );
4596
- ZVAL_LONG (p_width , ImageInfo .Thumbnail .width );
4597
- ZVAL_LONG (p_height , ImageInfo .Thumbnail .height );
4658
+ zval_dtor (z_width );
4659
+ zval_dtor (z_height );
4660
+ ZVAL_LONG (z_width , ImageInfo .Thumbnail .width );
4661
+ ZVAL_LONG (z_height , ImageInfo .Thumbnail .height );
4598
4662
}
4599
4663
if (arg_c >= 4 ) {
4600
- zval_dtor (p_imagetype );
4601
- ZVAL_LONG (p_imagetype , ImageInfo .Thumbnail .filetype );
4664
+ zval_dtor (z_imagetype );
4665
+ ZVAL_LONG (z_imagetype , ImageInfo .Thumbnail .filetype );
4602
4666
}
4603
4667
4604
4668
#ifdef EXIF_DEBUG
0 commit comments