Puede usar getimagesize
para obtener el tamaño y tipo de imagen. El tipo de imagen es el retorno en el índice pos 2.
1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (orden de bytes intel), 8 = TIFF (orden de bytes motorola), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM.
Php doc para getimagesize() - http://php.net/manual/en/function.getimagesize.php
Ejemplo de uso:
list($width, $height, $type) = getimagesize('herp-derp.png');
echo $type;
Editar: comentario útil a partir de notas PHPDoc ....
In addition to thomporter's quick-reference of the output array, here's what PHP 4.4.0 does:
Array[0] = Width
Array[1] = Height
Array[2] = Image Type Flag
Array[3] = width="xxx" height="xxx"
Array[bits] = bits
Array[channels] = channels
Array[mime] = mime-type
Editar :getImageType
devuelve una de las constantes IMAGICK_TYPE_ * (http://www.phpf1.com/manual/imagick-getimagetype.html). Puede encontrar la lista de constantes aquí: http://php.net/manual/en/imagick.constants.php.
imgtype constantes de
imagick :: IMGTYPE_UNDEFINED (integer)
imagick :: IMGTYPE_BILEVEL (integer)
imagick :: IMGTYPE_GRAYSCALE (integer)
imagick :: IMGTYPE_GRAYSCALEMATTE (integer)
imagick: : IMGTYPE_PALETTE (integer)
imagick :: IMGTYPE_PALETTEMATTE (integer)
imagick :: IMGTYPE_TRUECOLOR (número entero)
imagick :: IMGTYPE_TRUECOLORMATTE (entero)
imagick :: IMGTYPE_COLORSEPARATION (entero)
imagick :: IMGTYPE_COLORSEPARATIONMATTE (entero)
imagick :: IMGTYPE_OPTIMIZE (entero)
¿por qué quiere saber el formato? puedes establecer el formato a lo que sea, así que supongo que no sé por qué quieres el formato. – mcgrailm
Por un lado, si es un png transparente, no quiero guardarlo como un jpg, pero si es un jpg, no quiero aumentar el tamaño para guardarlo como png. – kylex
¿alguna de estas respuestas ha resuelto su problema? – mcgrailm