I hadn’t thought of list(). I've update the patch (attached) so that each value has both an indexed and associative entry in the returned array, so that it will still work with list().
Paul -----Original Message----- From: Alexey Shein [mailto:con...@gmail.com] Sent: 12 July 2011 10:44 To: Michael Wallner Cc: internals@lists.php.net Subject: Re: [PHP-DEV] [PATCH] getimagesize - return named keys for width, height, type and attributes 2011/7/12 Michael Wallner <m...@php.net>: > On Mon, 11 Jul 2011 22:33:31 +0100, Paul Dixon wrote: >> personally long term, I would aim to remove the position index >> entries completely. > > Which would make it unusable with list(). > +1 this will be huge BC break for this function. Please, don't remove position indexes. > > -- > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, > visit: http://www.php.net/unsub.php > > -- Regards, Shein Alexey -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php
diff --git a/ext/standard/image.c b/ext/standard/image.c index 5383667..1679c76 100644 --- a/ext/standard/image.c +++ b/ext/standard/image.c @@ -1361,19 +1361,37 @@ static void php_getimagesize_from_stream(php_stream *stream, zval **info, INTERN if (result) { array_init(return_value); + + /* index values */ 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); + add_index_string(return_value, 4, (char*)php_image_type_to_mime_type(itype), 1); + if (result->channels != 0) { + add_index_long(return_value, 5, result->channels); + } if (result->bits != 0) { - add_assoc_long(return_value, "bits", result->bits); + add_index_long(return_value, 6, result->bits); } + + /* assoc values */ + add_assoc_long(return_value, "width", result->width); + add_assoc_long(return_value, "height", result->height); + add_assoc_long(return_value, "type", itype); + add_assoc_string(return_value, "attributes", temp, 1); + add_assoc_string(return_value, "mime", (char*)php_image_type_to_mime_type(itype), 1); + 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); + if (result->bits != 0) { + add_assoc_long(return_value, "bits", result->bits); + } + efree(result); } else { RETURN_FALSE; diff --git a/ext/standard/tests/image/bug13213.phpt b/ext/standard/tests/image/bug13213.phpt index c97b701..d103cda 100644 --- a/ext/standard/tests/image/bug13213.phpt +++ b/ext/standard/tests/image/bug13213.phpt @@ -5,7 +5,7 @@ Bug #13213 (GetImageSize and wrong JPEG Comments) var_dump(GetImageSize(dirname(__FILE__).'/bug13213.jpg')); ?> --EXPECT-- -array(7) { +array(14) { [0]=> int(1) [1]=> @@ -14,10 +14,24 @@ array(7) { int(2) [3]=> string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> + [4]=> + string(10) "image/jpeg" + [5]=> int(3) + [6]=> + int(8) + ["width"]=> + int(1) + ["height"]=> + int(1) + ["type"]=> + int(2) + ["attributes"]=> + string(20) "width="1" height="1"" ["mime"]=> string(10) "image/jpeg" + ["channels"]=> + int(3) + ["bits"]=> + int(8) } diff --git a/ext/standard/tests/image/getimagesize.phpt b/ext/standard/tests/image/getimagesize.phpt index ab79c9c..dc4ff6a 100644 --- a/ext/standard/tests/image/getimagesize.phpt +++ b/ext/standard/tests/image/getimagesize.phpt @@ -25,7 +25,7 @@ GetImageSize() --EXPECT-- array(11) { ["test1pix.bmp"]=> - array(6) { + array(12) { [0]=> int(1) [1]=> @@ -34,13 +34,25 @@ array(11) { int(6) [3]=> string(20) "width="1" height="1"" - ["bits"]=> + [4]=> + string(14) "image/x-ms-bmp" + [6]=> int(24) + ["width"]=> + int(1) + ["height"]=> + int(1) + ["type"]=> + int(6) + ["attributes"]=> + string(20) "width="1" height="1"" ["mime"]=> string(14) "image/x-ms-bmp" + ["bits"]=> + int(24) } ["test1pix.jp2"]=> - array(7) { + array(14) { [0]=> int(1) [1]=> @@ -49,15 +61,29 @@ array(11) { int(10) [3]=> string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> + [4]=> + string(9) "image/jp2" + [5]=> int(3) + [6]=> + int(8) + ["width"]=> + int(1) + ["height"]=> + int(1) + ["type"]=> + int(10) + ["attributes"]=> + string(20) "width="1" height="1"" ["mime"]=> string(9) "image/jp2" + ["channels"]=> + int(3) + ["bits"]=> + int(8) } ["test1pix.jpc"]=> - array(7) { + array(14) { [0]=> int(1) [1]=> @@ -66,15 +92,29 @@ array(11) { int(9) [3]=> string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> + [4]=> + string(24) "application/octet-stream" + [5]=> int(3) + [6]=> + int(8) + ["width"]=> + int(1) + ["height"]=> + int(1) + ["type"]=> + int(9) + ["attributes"]=> + string(20) "width="1" height="1"" ["mime"]=> string(24) "application/octet-stream" + ["channels"]=> + int(3) + ["bits"]=> + int(8) } ["test1pix.jpg"]=> - array(7) { + array(14) { [0]=> int(1) [1]=> @@ -83,15 +123,29 @@ array(11) { int(2) [3]=> string(20) "width="1" height="1"" - ["bits"]=> - int(8) - ["channels"]=> + [4]=> + string(10) "image/jpeg" + [5]=> int(3) + [6]=> + int(8) + ["width"]=> + int(1) + ["height"]=> + int(1) + ["type"]=> + int(2) + ["attributes"]=> + string(20) "width="1" height="1"" ["mime"]=> string(10) "image/jpeg" + ["channels"]=> + int(3) + ["bits"]=> + int(8) } ["test2pix.gif"]=> - array(7) { + array(14) { [0]=> int(2) [1]=> @@ -100,15 +154,29 @@ array(11) { int(1) [3]=> string(20) "width="2" height="1"" - ["bits"]=> - int(1) - ["channels"]=> + [4]=> + string(9) "image/gif" + [5]=> int(3) + [6]=> + int(1) + ["width"]=> + int(2) + ["height"]=> + int(1) + ["type"]=> + int(1) + ["attributes"]=> + string(20) "width="2" height="1"" ["mime"]=> string(9) "image/gif" + ["channels"]=> + int(3) + ["bits"]=> + int(1) } ["test4pix.gif"]=> - array(7) { + array(14) { [0]=> int(4) [1]=> @@ -117,15 +185,29 @@ array(11) { int(1) [3]=> string(20) "width="4" height="1"" - ["bits"]=> - int(2) - ["channels"]=> + [4]=> + string(9) "image/gif" + [5]=> int(3) + [6]=> + int(2) + ["width"]=> + int(4) + ["height"]=> + int(1) + ["type"]=> + int(1) + ["attributes"]=> + string(20) "width="4" height="1"" ["mime"]=> string(9) "image/gif" + ["channels"]=> + int(3) + ["bits"]=> + int(2) } ["test4pix.iff"]=> - array(6) { + array(12) { [0]=> int(4) [1]=> @@ -134,13 +216,25 @@ array(11) { int(14) [3]=> string(20) "width="4" height="1"" - ["bits"]=> + [4]=> + string(9) "image/iff" + [6]=> int(4) + ["width"]=> + int(4) + ["height"]=> + int(1) + ["type"]=> + int(14) + ["attributes"]=> + string(20) "width="4" height="1"" ["mime"]=> string(9) "image/iff" + ["bits"]=> + int(4) } ["test4pix.png"]=> - array(6) { + array(12) { [0]=> int(4) [1]=> @@ -149,13 +243,25 @@ array(11) { int(3) [3]=> string(20) "width="4" height="1"" - ["bits"]=> + [4]=> + string(9) "image/png" + [6]=> + int(4) + ["width"]=> int(4) + ["height"]=> + int(1) + ["type"]=> + int(3) + ["attributes"]=> + string(20) "width="4" height="1"" ["mime"]=> string(9) "image/png" + ["bits"]=> + int(4) } ["test4pix.psd"]=> - array(5) { + array(10) { [0]=> int(4) [1]=> @@ -164,11 +270,21 @@ array(11) { int(5) [3]=> string(20) "width="4" height="1"" + [4]=> + string(9) "image/psd" + ["width"]=> + int(4) + ["height"]=> + int(1) + ["type"]=> + int(5) + ["attributes"]=> + string(20) "width="4" height="1"" ["mime"]=> string(9) "image/psd" } ["test4pix.swf"]=> - array(5) { + array(10) { [0]=> int(550) [1]=> @@ -177,11 +293,21 @@ array(11) { int(4) [3]=> string(24) "width="550" height="400"" + [4]=> + string(29) "application/x-shockwave-flash" + ["width"]=> + int(550) + ["height"]=> + int(400) + ["type"]=> + int(4) + ["attributes"]=> + string(24) "width="550" height="400"" ["mime"]=> string(29) "application/x-shockwave-flash" } ["test4pix.tif"]=> - array(5) { + array(10) { [0]=> int(4) [1]=> @@ -190,7 +316,17 @@ array(11) { int(7) [3]=> string(20) "width="4" height="1"" + [4]=> + string(10) "image/tiff" + ["width"]=> + int(4) + ["height"]=> + int(1) + ["type"]=> + int(7) + ["attributes"]=> + string(20) "width="4" height="1"" ["mime"]=> string(10) "image/tiff" } -} +} \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesize_246x247.phpt b/ext/standard/tests/image/getimagesize_246x247.phpt index e5a0aea..3979db4 100644 --- a/ext/standard/tests/image/getimagesize_246x247.phpt +++ b/ext/standard/tests/image/getimagesize_246x247.phpt @@ -25,7 +25,7 @@ GetImageSize() with 246x247 pixels --EXPECT-- array(1) { ["246x247.png"]=> - array(6) { + array(12) { [0]=> int(246) [1]=> @@ -34,9 +34,21 @@ array(1) { int(3) [3]=> string(24) "width="246" height="247"" - ["bits"]=> + [4]=> + string(9) "image/png" + [6]=> int(4) + ["width"]=> + int(246) + ["height"]=> + int(247) + ["type"]=> + int(3) + ["attributes"]=> + string(24) "width="246" height="247"" ["mime"]=> string(9) "image/png" + ["bits"]=> + int(4) } -} +} \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesize_384x385.phpt b/ext/standard/tests/image/getimagesize_384x385.phpt index 0051df7..ffaf998 100644 --- a/ext/standard/tests/image/getimagesize_384x385.phpt +++ b/ext/standard/tests/image/getimagesize_384x385.phpt @@ -25,7 +25,7 @@ GetImageSize() with 384x385 pixels --EXPECT-- array(1) { ["384x385.png"]=> - array(6) { + array(12) { [0]=> int(384) [1]=> @@ -34,9 +34,21 @@ array(1) { int(3) [3]=> string(24) "width="384" height="385"" - ["bits"]=> + [4]=> + string(9) "image/png" + [6]=> int(1) + ["width"]=> + int(384) + ["height"]=> + int(385) + ["type"]=> + int(3) + ["attributes"]=> + string(24) "width="384" height="385"" ["mime"]=> string(9) "image/png" + ["bits"]=> + int(1) } -} +} \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesize_basic.phpt b/ext/standard/tests/image/getimagesize_basic.phpt index 4d47225..26c2d75 100644 Binary files a/ext/standard/tests/image/getimagesize_basic.phpt and b/ext/standard/tests/image/getimagesize_basic.phpt differ diff --git a/ext/standard/tests/image/getimagesize_swc.phpt b/ext/standard/tests/image/getimagesize_swc.phpt index f8c7449..8732c06 100644 --- a/ext/standard/tests/image/getimagesize_swc.phpt +++ b/ext/standard/tests/image/getimagesize_swc.phpt @@ -11,7 +11,7 @@ GetImageSize() for compressed swf files var_dump(getimagesize(dirname(__FILE__) . "/test13pix.swf")); ?> --EXPECT-- -array(5) { +array(10) { [0]=> int(550) [1]=> @@ -20,6 +20,16 @@ array(5) { int(13) [3]=> string(24) "width="550" height="400"" + [4]=> + string(29) "application/x-shockwave-flash" + ["width"]=> + int(550) + ["height"]=> + int(400) + ["type"]=> + int(13) + ["attributes"]=> + string(24) "width="550" height="400"" ["mime"]=> string(29) "application/x-shockwave-flash" -} +} \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesize_tif_mm.phpt b/ext/standard/tests/image/getimagesize_tif_mm.phpt index 8bc88fd..5f12495 100644 --- a/ext/standard/tests/image/getimagesize_tif_mm.phpt +++ b/ext/standard/tests/image/getimagesize_tif_mm.phpt @@ -22,7 +22,7 @@ var_dump($arr); ===DONE=== --EXPECT-- *** Testing getimagesize() : tiff_mm format *** -array(5) { +array(10) { [0]=> int(2) [1]=> @@ -31,6 +31,16 @@ array(5) { int(8) [3]=> string(20) "width="2" height="2"" + [4]=> + string(10) "image/tiff" + ["width"]=> + int(2) + ["height"]=> + int(2) + ["type"]=> + int(8) + ["attributes"]=> + string(20) "width="2" height="2"" ["mime"]=> string(10) "image/tiff" } diff --git a/ext/standard/tests/image/getimagesize_variation4.phpt b/ext/standard/tests/image/getimagesize_variation4.phpt index 8fa690c..6ab3455 100644 --- a/ext/standard/tests/image/getimagesize_variation4.phpt +++ b/ext/standard/tests/image/getimagesize_variation4.phpt @@ -21,7 +21,7 @@ var_dump( $info ); ===DONE=== --EXPECTF-- *** Testing getimagesize() : variation *** -array(5) { +array(10) { [0]=> int(550) [1]=> @@ -30,6 +30,16 @@ array(5) { int(13) [3]=> string(24) "width="550" height="400"" + [4]=> + string(29) "application/x-shockwave-flash" + ["width"]=> + int(550) + ["height"]=> + int(400) + ["type"]=> + int(13) + ["attributes"]=> + string(24) "width="550" height="400"" ["mime"]=> string(29) "application/x-shockwave-flash" } diff --git a/ext/standard/tests/image/getimagesize_variation_005.phpt b/ext/standard/tests/image/getimagesize_variation_005.phpt index 6f0ad8f..ef245aa 100644 --- a/ext/standard/tests/image/getimagesize_variation_005.phpt +++ b/ext/standard/tests/image/getimagesize_variation_005.phpt @@ -21,7 +21,7 @@ var_dump( $info ); ===DONE=== --EXPECTF-- *** Testing getimagesize() : basic functionality *** -array(5) { +array(10) { [0]=> int(550) [1]=> @@ -30,6 +30,16 @@ array(5) { int(13) [3]=> string(24) "width="550" height="400"" + [4]=> + string(29) "application/x-shockwave-flash" + ["width"]=> + int(550) + ["height"]=> + int(400) + ["type"]=> + int(13) + ["attributes"]=> + string(24) "width="550" height="400"" ["mime"]=> string(29) "application/x-shockwave-flash" } diff --git a/ext/standard/tests/image/getimagesize_wbmp.phpt b/ext/standard/tests/image/getimagesize_wbmp.phpt index 503b5f1..39f9615 100644 --- a/ext/standard/tests/image/getimagesize_wbmp.phpt +++ b/ext/standard/tests/image/getimagesize_wbmp.phpt @@ -22,7 +22,7 @@ var_dump($arr); ===DONE=== --EXPECT-- *** Testing getimagesize() : wbmp format *** -array(5) { +array(10) { [0]=> int(75) [1]=> @@ -31,9 +31,19 @@ array(5) { int(15) [3]=> string(22) "width="75" height="50"" + [4]=> + string(18) "image/vnd.wap.wbmp" + ["width"]=> + int(75) + ["height"]=> + int(50) + ["type"]=> + int(15) + ["attributes"]=> + string(22) "width="75" height="50"" ["mime"]=> string(18) "image/vnd.wap.wbmp" } array(0) { } -===DONE=== +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesize_xbm.phpt b/ext/standard/tests/image/getimagesize_xbm.phpt index 53406a8..d8d8552 100644 --- a/ext/standard/tests/image/getimagesize_xbm.phpt +++ b/ext/standard/tests/image/getimagesize_xbm.phpt @@ -22,7 +22,7 @@ var_dump($arr); ===DONE=== --EXPECT-- *** Testing getimagesize() : xbm format *** -array(5) { +array(10) { [0]=> int(75) [1]=> @@ -31,9 +31,19 @@ array(5) { int(16) [3]=> string(22) "width="75" height="50"" + [4]=> + string(9) "image/xbm" + ["width"]=> + int(75) + ["height"]=> + int(50) + ["type"]=> + int(16) + ["attributes"]=> + string(22) "width="75" height="50"" ["mime"]=> string(9) "image/xbm" } array(0) { } -===DONE=== +===DONE=== \ No newline at end of file diff --git a/ext/standard/tests/image/getimagesizefromstring1.phpt b/ext/standard/tests/image/getimagesizefromstring1.phpt index df75be5..60410ff 100644 --- a/ext/standard/tests/image/getimagesizefromstring1.phpt +++ b/ext/standard/tests/image/getimagesizefromstring1.phpt @@ -14,7 +14,7 @@ var_dump($i1); var_dump($i2); ?> --EXPECT-- -array(7) { +array(14) { [0]=> int(120) [1]=> @@ -23,14 +23,28 @@ array(7) { int(1) [3]=> string(23) "width="120" height="67"" - ["bits"]=> - int(7) - ["channels"]=> + [4]=> + string(9) "image/gif" + [5]=> int(3) + [6]=> + int(7) + ["width"]=> + int(120) + ["height"]=> + int(67) + ["type"]=> + int(1) + ["attributes"]=> + string(23) "width="120" height="67"" ["mime"]=> string(9) "image/gif" + ["channels"]=> + int(3) + ["bits"]=> + int(7) } -array(7) { +array(14) { [0]=> int(120) [1]=> @@ -39,11 +53,24 @@ array(7) { int(1) [3]=> string(23) "width="120" height="67"" - ["bits"]=> - int(7) - ["channels"]=> + [4]=> + string(9) "image/gif" + [5]=> int(3) + [6]=> + int(7) + ["width"]=> + int(120) + ["height"]=> + int(67) + ["type"]=> + int(1) + ["attributes"]=> + string(23) "width="120" height="67"" ["mime"]=> string(9) "image/gif" -} - + ["channels"]=> + int(3) + ["bits"]=> + int(7) +} \ No newline at end of file
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php