Re: Re: how to detect type of image

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 28.04.2007 10:39, Tijnema ! wrote:
First of all, i don't see any reason why this works better then other
functions, as it also relies on the magic bytes.

Second, for your switch, you should use the constants
(IMAGETYPE_GIF,IMAGETYPE_JPEG,...) instead of just using decimal
values.

Tijnema

Yes, I wrote this function because none of the others worked for me
properly. I found functions which determined the file type by a given
extension. Those file types can be easily faked by using an other extension.
I wrote the function a long time ago and was using PHP 4. The IMAGETYPE
constants are available since PHP 4.3.0.

It should, but instead try this:

$image_size = getimagesize($filename);
echo $image_size['mime'];

I needed a way to get the correct extension of an image file.
It is possible to create an array with all MIME types and the matching
extensions. Then you just have to search for $image_size['mime'] in it and you have correct extension. As I see there is a way,
which is a lot easier: You can use $image_size[2] which is a flag
indicating type of the image.

1 = GIF
2 = JPG
3 = PNG
4 = SWF,
5 = PSD
6 = BMP
7 = TIFF(intel byte order)
8 = TIFF(motorola byte order)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = IFF
15 = WBMP
16 = XBM

Since PHP 4.3.0 you can use constants.

I reckon
  $type = exif_imagetype($filename);
is the same as
  $image_size = getimagesize($filename);
  $type = $image_size[2];

exif_imagetype would have to be faster than getimagesize because it only
gets the file type. getimagesize does also get the width/height, MIME
type, etc. I think getimagesize depends on exif_imagetype and will work even if exif is disabled, but I am not sure.

Tim

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux