php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #35783 Using GetImageSize with ICO files and the image/vnd.microsoft.icon mime type
Submitted: 2005-12-23 09:37 UTC Modified: 2016-10-07 22:26 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: brian at gtv dot com Assigned: cmb (profile)
Status: Closed Package: GetImageSize related
PHP Version: 5.1.1 OS: FreeBSD 5.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
20 + 18 = ?
Subscribe to this entry?

 
 [2005-12-23 09:37 UTC] brian at gtv dot com
Description:
------------
I am using the GetImageSize function in a function I wrote which validates the width, height, and type of an image as the user uploads it to my website. On my website I have setup a number of different fields where a user can upload different images that are very specific to the width, height, and type that I allow for each field.

For example in field one I allow the user to upload an image of width=512, height=315, and type=BMP and in field two I allow the user to upload an image of width=48, height=48, and type=ICO and in field three I allow the user to upload an image of width=176, height=36, and type=GIF.

My problem is that the GetImageSize function does not currently support the ICO file type and the image/vnd.microsoft.icon mime type. When I upload a ICO image and use the GetImageSize function on the image the $image_size_array[0], $image_size_array[1], and $image_size_array[2] are blank as well as the $image_size_array['mime'] being blank.

This means I can't validate the width, height, or file type of the ICO images that are being uploaded. Which defeats the purpose of validating the files for a good number of the images in this section of my website.

From my review of the bug report DB I have not seen anyone else report this problem and I'm a little shocked to see that no one else would need support for ICO images in PHP. It may just be the type of website I'm building and the type of company I work for - a software company - where we are using these ICO images that are uploaded from our customers in our software. However I think it would be a good idea to add support into PHP for this fairly common image format that is widely used.

Reproduce code:
---------------
function validateGraphic($image, $width, $height, $type){
	$err_text = "";
	if(!isset($image)) { $err_text .= "You must select an image file to upload.<br>\n"; }
	if($image['error'] > '0') { $err_text .= "There was an error uploading the image file.<br>\n"; }
	if($image['error'] == '0') {
		$image_size_array = getimagesize($image['tmp_name']);
		//check the width of the image
		if($image_size_array[0] > $width) { $err_text .= "Image is too wide. It is {$image_size_array[0]} pixels wide.<br>\n"; } 
		if($image_size_array[0] < $width) { $err_text .= "Image is too narrow. It is {$image_size_array[0]} pixels wide.<br>\n"; }
		//check the height of the image
		if($image_size_array[1] > $height) { $err_text .= "Image is too tall. It is {$image_size_array[1]} pixels tall.<br>\n"; }
		if($image_size_array[1] < $height) { $err_text .= "Image is too short. It is {$image_size_array[1]} pixels tall.<br>\n"; }
		//check the type of the image
		switch($image_size_array['mime']) {
			case 'image/gif':
				if($type != "GIF") { $err_text .= "Image is wrong type. It is a GIF and should be a {$type}.<br>\n"; }
				break;
			case 'image/jpeg':
				if($type != "JPG") { $err_text .= "Image is wrong type. It is a JPG and should be a {$type}.<br>\n"; }
				break;
			case 'image/vnd.microsoft.icon':
				if($type != "ICO") { $err_text .= "Image is wrong type. It is a ICO and should be a {$type}.<br>\n"; }
				break;
			case 'image/bmp':
				if($type != "BMP") { $err_text .= "Image is wrong type. It is a BMP and should be a {$type}.<br>\n"; }
				break;
			default:
				$err_text .= "Image is wrong type. It is a {$image_size_array['mime']} and should be a {$type}.<br>\n";
				break;
		}
	}
	return $err_text;
}

This function is called in this type of manner:
$error_txt .= validateGraphic($_FILES['upload1'], '142', '114', 'ICO');

Expected result:
----------------
When function is called in manner described and the ICO image that matches is uploaded I expect no error messages to be produced, the file to be uploaded, and the entry to be added into my DB. 

I'm expecting the GetImageSize function to handle the ICO file type and the image/vnd.microsoft.icon mime type, but because it can't this is breaking my validation function.

Actual result:
--------------
Instead I get the following error messages:
Image is too narrow. It is pixels wide.
Image is too short. It is pixels tall.
Image is wrong type. It is a and should be a ICO.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-12-29 08:13 UTC] brian at gtv dot com
You can add the following code to the Switch / Case statement in the Reproduce code included above. It's a different mime type that can also be used to identify ICO images. The addition of this code does not resolve the problem. It is only to highlight the subtleties of the issue and to help make it easier getting the new feature added. Here's the additional Case statement:

			case 'image/x-icon': 
				if($type != "ICO") { $err_text .= "Image is wrong type. It is a ICO and should be a {$type}.<br>\n"; }
				break;
 [2009-11-01 03:51 UTC] cuisdy at gmail dot com
@brian at gtv dot com: getimagesize doesn't return anything in the ['mime'] index either.
 [2011-04-08 21:45 UTC] jani@php.net
-Package: Feature/Change Request +Package: GetImageSize related
 [2016-10-07 22:26 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-10-07 22:26 UTC] cmb@php.net
Support for ICO is supposed to be available as of PHP 5.3.0, see
<http://php.net/ChangeLog-5.php#5.3.0>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Apr 24 07:01:29 2024 UTC