1999-04-17 08:37:12 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
1999-07-16 21:13:16 +08:00
|
|
|
| PHP version 4.0 |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2001-02-26 14:11:02 +08:00
|
|
|
| Copyright (c) 1997-2001 The PHP Group |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2000-05-18 23:34:45 +08:00
|
|
|
| This source file is subject to version 2.02 of the PHP license, |
|
1999-07-16 21:13:16 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
|
|
|
| available at through the world-wide-web at |
|
2000-05-18 23:34:45 +08:00
|
|
|
| http://www.php.net/license/2_02.txt. |
|
1999-07-16 21:13:16 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
1999-04-17 08:37:12 +08:00
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Authors: Rasmus Lerdorf |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
/* $Id$ */
|
2001-05-04 05:28:26 +08:00
|
|
|
/*
|
1999-04-17 08:37:12 +08:00
|
|
|
* Based on Daniel Schmitt's imageinfo.c which carried the following
|
|
|
|
* Copyright notice.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* imageinfo.c
|
|
|
|
*
|
|
|
|
* Simple routines to extract image width/height data from GIF/JPEG files.
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997 Daniel Schmitt, opal online publishing, Bonn, Germany.
|
|
|
|
*
|
2001-05-04 05:28:26 +08:00
|
|
|
* Includes code snippets from rdjpgcom.c,
|
1999-04-17 08:37:12 +08:00
|
|
|
* Copyright (c) 1994-1995 Thomas G. Lane
|
|
|
|
* from release 6a of the Independent JPEG Group's software.
|
|
|
|
*
|
|
|
|
* Legal status: see GNU General Public License version 2 or later.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "php.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#if HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
2001-02-24 06:07:16 +08:00
|
|
|
#include "fopen_wrappers.h"
|
2001-01-20 00:52:40 +08:00
|
|
|
#include "ext/standard/fsock.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
#if HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1999-09-02 19:58:23 +08:00
|
|
|
#include "php_image.h"
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* file type markers */
|
2001-02-21 02:00:44 +08:00
|
|
|
PHPAPI const char php_sig_gif[3] = {'G', 'I', 'F'};
|
2001-05-04 05:28:26 +08:00
|
|
|
PHPAPI const char php_sig_psd[4] = {'8', 'B', 'P', 'S'};
|
|
|
|
PHPAPI const char php_sig_bmp[2] = {'B', 'M'};
|
2001-02-21 02:00:44 +08:00
|
|
|
PHPAPI const char php_sig_swf[3] = {'F', 'W', 'S'};
|
|
|
|
PHPAPI const char php_sig_jpg[3] = {(char) 0xff, (char) 0xd8, (char) 0xff};
|
2001-05-04 05:28:26 +08:00
|
|
|
PHPAPI const char php_sig_png[8] = {(char) 0x89, (char) 0x50, (char) 0x4e, (char) 0x47,
|
2001-02-21 02:00:44 +08:00
|
|
|
(char) 0x0d, (char) 0x0a, (char) 0x1a, (char) 0x0a};
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* return info as a struct, to make expansion easier */
|
|
|
|
|
|
|
|
struct gfxinfo {
|
|
|
|
unsigned int width;
|
|
|
|
unsigned int height;
|
1999-09-02 19:58:23 +08:00
|
|
|
unsigned int bits;
|
|
|
|
unsigned int channels;
|
1999-04-17 08:37:12 +08:00
|
|
|
};
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_gif
|
|
|
|
* routine to handle GIF files. If only everything were that easy... ;} */
|
2001-01-20 00:52:40 +08:00
|
|
|
static struct gfxinfo *php_handle_gif (int socketd, FILE *fp, int issock)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
|
|
|
unsigned char a[2];
|
2001-01-20 00:52:40 +08:00
|
|
|
char temp[3];
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-01-20 00:52:40 +08:00
|
|
|
FP_FREAD(temp, 3, socketd, fp, issock); /* fseek(fp, 6L, SEEK_SET); */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
|
2001-01-20 00:52:40 +08:00
|
|
|
result->width = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
|
2001-01-20 00:52:40 +08:00
|
|
|
result->height = (unsigned short)a[0] | (((unsigned short)a[1])<<8);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-01-20 00:52:40 +08:00
|
|
|
return result;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_psd
|
|
|
|
*/
|
2001-05-04 05:28:26 +08:00
|
|
|
static struct gfxinfo *php_handle_psd (int socketd, FILE *fp, int issock)
|
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
|
|
|
unsigned char a[8];
|
|
|
|
char temp[11];
|
|
|
|
unsigned long in_width, in_height;
|
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
|
2001-05-04 05:28:26 +08:00
|
|
|
FP_FREAD(temp, sizeof(temp), socketd, fp, issock);
|
|
|
|
|
|
|
|
if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) {
|
|
|
|
in_height = 0;
|
|
|
|
in_width = 0;
|
|
|
|
} else {
|
|
|
|
in_height = (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]);
|
|
|
|
in_width = (((unsigned long) a[ 4 ]) << 24) + (((unsigned long) a[ 5 ]) << 16) + (((unsigned long) a[ 6 ]) << 8) + ((unsigned long) a[ 7 ]);
|
|
|
|
}
|
|
|
|
|
|
|
|
result->width = (unsigned int) in_width;
|
|
|
|
result->height = (unsigned int) in_height;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_bmp
|
|
|
|
*/
|
2001-05-04 05:28:26 +08:00
|
|
|
static struct gfxinfo *php_handle_bmp (int socketd, FILE *fp, int issock)
|
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
|
|
|
char temp[15];
|
|
|
|
|
|
|
|
struct {
|
|
|
|
unsigned long in_width, in_height;
|
|
|
|
} dim;
|
|
|
|
|
|
|
|
result = (struct gfxinfo *) ecalloc (1, sizeof(struct gfxinfo));
|
|
|
|
|
|
|
|
FP_FREAD(temp, sizeof(temp), socketd, fp, issock);
|
|
|
|
FP_FREAD((char*) &dim, sizeof(dim), socketd, fp, issock);
|
|
|
|
result->width = dim.in_width;
|
|
|
|
result->height = dim.in_height;
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_swf_get_bits
|
|
|
|
* routines to handle SWF files. */
|
2000-08-12 07:24:54 +08:00
|
|
|
static unsigned long int php_swf_get_bits (unsigned char* buffer, unsigned int pos, unsigned int count)
|
2000-06-05 02:29:15 +08:00
|
|
|
{
|
|
|
|
unsigned int loop;
|
|
|
|
unsigned long int result = 0;
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2000-06-05 02:29:15 +08:00
|
|
|
for (loop = pos; loop < pos + count; loop++)
|
|
|
|
{
|
2001-05-04 05:28:26 +08:00
|
|
|
result = result +
|
2000-06-05 02:29:15 +08:00
|
|
|
((((buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (count - (loop - pos) - 1));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-06-05 02:29:15 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_swf
|
|
|
|
*/
|
2001-01-20 00:52:40 +08:00
|
|
|
static struct gfxinfo *php_handle_swf (int socketd, FILE *fp, int issock)
|
2000-06-05 02:29:15 +08:00
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
2000-06-19 04:09:17 +08:00
|
|
|
long bits;
|
2000-06-05 02:29:15 +08:00
|
|
|
unsigned char a[32];
|
2001-01-20 00:52:40 +08:00
|
|
|
char temp[5];
|
|
|
|
|
2000-06-05 02:29:15 +08:00
|
|
|
result = (struct gfxinfo *) ecalloc (1, sizeof (struct gfxinfo));
|
2001-01-20 00:52:40 +08:00
|
|
|
FP_FREAD(temp, 5, socketd, fp, issock); /* fseek(fp, 8L, SEEK_SET); */
|
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
FP_FREAD(a, sizeof(a), socketd, fp, issock); /* fread(a, sizeof(a), 1, fp); */
|
2000-06-05 02:29:15 +08:00
|
|
|
bits = php_swf_get_bits (a, 0, 5);
|
|
|
|
result->width = (php_swf_get_bits (a, 5 + bits, bits) -
|
|
|
|
php_swf_get_bits (a, 5, bits)) / 20;
|
|
|
|
result->height = (php_swf_get_bits (a, 5 + (3 * bits), bits) -
|
|
|
|
php_swf_get_bits (a, 5 + (2 * bits), bits)) / 20;
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
2000-06-05 02:29:15 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_png
|
|
|
|
* routine to handle PNG files */
|
2001-01-20 00:52:40 +08:00
|
|
|
static struct gfxinfo *php_handle_png (int socketd, FILE *fp, int issock)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
|
|
|
unsigned long in_width, in_height;
|
2001-01-20 00:52:40 +08:00
|
|
|
char temp[8];
|
|
|
|
unsigned char a[8];
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
|
2001-01-20 00:52:40 +08:00
|
|
|
|
|
|
|
FP_FREAD(temp, sizeof(temp), socketd, fp, issock); /* fseek(fp, 16L, SEEK_SET); */
|
|
|
|
|
2001-05-04 05:28:26 +08:00
|
|
|
if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) {
|
2001-01-20 00:52:40 +08:00
|
|
|
in_width = 0;
|
|
|
|
in_height = 0;
|
|
|
|
} else {
|
|
|
|
in_width = (((unsigned long) a[ 0 ]) << 24) + (((unsigned long) a[ 1 ]) << 16) + (((unsigned long) a[ 2 ]) << 8) + ((unsigned long) a[ 3 ]);
|
|
|
|
in_height = (((unsigned long) a[ 4 ]) << 24) + (((unsigned long) a[ 5 ]) << 16) + (((unsigned long) a[ 6 ]) << 8) + ((unsigned long) a[ 7 ]);
|
2001-05-04 05:28:26 +08:00
|
|
|
}
|
2001-01-20 00:52:40 +08:00
|
|
|
|
|
|
|
result->width = (unsigned int) in_width;
|
1999-04-17 08:37:12 +08:00
|
|
|
result->height = (unsigned int) in_height;
|
|
|
|
return result;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* routines to handle JPEG data */
|
|
|
|
|
|
|
|
/* some defines for the different JPEG block types */
|
|
|
|
#define M_SOF0 0xC0 /* Start Of Frame N */
|
|
|
|
#define M_SOF1 0xC1 /* N indicates which compression process */
|
|
|
|
#define M_SOF2 0xC2 /* Only SOF0-SOF2 are now in common use */
|
|
|
|
#define M_SOF3 0xC3
|
|
|
|
#define M_SOF5 0xC5 /* NB: codes C4 and CC are NOT SOF markers */
|
|
|
|
#define M_SOF6 0xC6
|
|
|
|
#define M_SOF7 0xC7
|
|
|
|
#define M_SOF9 0xC9
|
|
|
|
#define M_SOF10 0xCA
|
|
|
|
#define M_SOF11 0xCB
|
|
|
|
#define M_SOF13 0xCD
|
|
|
|
#define M_SOF14 0xCE
|
|
|
|
#define M_SOF15 0xCF
|
2001-05-04 05:28:26 +08:00
|
|
|
#define M_SOI 0xD8
|
1999-04-17 08:37:12 +08:00
|
|
|
#define M_EOI 0xD9 /* End Of Image (end of datastream) */
|
|
|
|
#define M_SOS 0xDA /* Start Of Scan (begins compressed data) */
|
|
|
|
#define M_APP0 0xe0
|
|
|
|
#define M_APP1 0xe1
|
|
|
|
#define M_APP2 0xe2
|
|
|
|
#define M_APP3 0xe3
|
|
|
|
#define M_APP4 0xe4
|
|
|
|
#define M_APP5 0xe5
|
|
|
|
#define M_APP6 0xe6
|
|
|
|
#define M_APP7 0xe7
|
|
|
|
#define M_APP8 0xe8
|
|
|
|
#define M_APP9 0xe9
|
|
|
|
#define M_APP10 0xea
|
|
|
|
#define M_APP11 0xeb
|
|
|
|
#define M_APP12 0xec
|
|
|
|
#define M_APP13 0xed
|
|
|
|
#define M_APP14 0xee
|
|
|
|
#define M_APP15 0xef
|
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_read2
|
|
|
|
*/
|
2001-01-20 00:52:40 +08:00
|
|
|
static unsigned short php_read2(int socketd, FILE *fp, int issock)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2001-01-20 00:52:40 +08:00
|
|
|
unsigned char a[2];
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* just return 0 if we hit the end-of-file */
|
2001-01-20 00:52:40 +08:00
|
|
|
if((FP_FREAD(a, sizeof(a), socketd, fp, issock)) <= 0) return 0;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
return (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]);
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_next_marker
|
|
|
|
*/
|
2001-01-20 00:52:40 +08:00
|
|
|
static unsigned int php_next_marker(int socketd, FILE *fp, int issock)
|
1999-04-17 08:37:12 +08:00
|
|
|
/* get next marker byte from file */
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
/* get marker byte, swallowing possible padding */
|
|
|
|
do {
|
2001-08-12 01:03:37 +08:00
|
|
|
if ((c = FP_FGETC(socketd, fp, issock)) == EOF)
|
1999-04-17 08:37:12 +08:00
|
|
|
return M_EOI; /* we hit EOF */
|
|
|
|
} while (c == 0xff);
|
|
|
|
|
|
|
|
return (unsigned int) c;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_skip_variable
|
|
|
|
*/
|
2001-01-20 00:52:40 +08:00
|
|
|
static void php_skip_variable(int socketd, FILE *fp, int issock)
|
1999-04-17 08:37:12 +08:00
|
|
|
/* skip over a variable-length block; assumes proper length marker */
|
|
|
|
{
|
|
|
|
unsigned short length;
|
2001-01-20 00:52:40 +08:00
|
|
|
char *tmp;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
length = php_read2(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
length -= 2; /* length includes itself */
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2001-01-20 00:52:40 +08:00
|
|
|
tmp = emalloc(length);
|
|
|
|
FP_FREAD(tmp, (long) length, socketd, fp, issock); /* skip the header */
|
|
|
|
efree(tmp);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_read_APP
|
|
|
|
*/
|
2001-09-04 14:08:42 +08:00
|
|
|
static void php_read_APP(int socketd, FILE *fp, int issock, unsigned int marker, zval *info)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
unsigned short length;
|
|
|
|
unsigned char *buffer;
|
|
|
|
unsigned char markername[ 16 ];
|
2000-07-29 23:29:35 +08:00
|
|
|
zval *tmp;
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
length = php_read2(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
length -= 2; /* length includes itself */
|
|
|
|
|
2001-04-20 23:37:55 +08:00
|
|
|
buffer = emalloc(length);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-01-20 00:52:40 +08:00
|
|
|
if (FP_FREAD(buffer, (long) length, socketd, fp, issock) <= 0) {
|
|
|
|
efree(buffer);
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-08-12 01:03:37 +08:00
|
|
|
sprintf(markername, "APP%d", marker - M_APP0);
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2000-07-29 23:29:35 +08:00
|
|
|
if (zend_hash_find(info->value.ht, markername, strlen(markername)+1, (void **) &tmp) == FAILURE) {
|
|
|
|
/* XXX we onyl catch the 1st tag of it's kind! */
|
2001-08-12 01:03:37 +08:00
|
|
|
add_assoc_stringl(info, markername, buffer, length, 1);
|
2000-07-29 23:29:35 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
efree(buffer);
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
2001-06-06 21:06:12 +08:00
|
|
|
/* {{{ php_handle_jpeg
|
|
|
|
main loop to parse JPEG structure */
|
2001-01-20 00:52:40 +08:00
|
|
|
static struct gfxinfo *php_handle_jpeg (int socketd, FILE *fp, int issock, pval *info)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
|
|
|
struct gfxinfo *result = NULL;
|
|
|
|
unsigned int marker;
|
2001-01-20 00:52:40 +08:00
|
|
|
char tmp[2];
|
|
|
|
unsigned char a[4];
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
for (;;) {
|
2001-08-12 01:03:37 +08:00
|
|
|
marker = php_next_marker(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
switch (marker) {
|
|
|
|
case M_SOF0:
|
|
|
|
case M_SOF1:
|
|
|
|
case M_SOF2:
|
|
|
|
case M_SOF3:
|
|
|
|
case M_SOF5:
|
|
|
|
case M_SOF6:
|
|
|
|
case M_SOF7:
|
|
|
|
case M_SOF9:
|
|
|
|
case M_SOF10:
|
|
|
|
case M_SOF11:
|
|
|
|
case M_SOF13:
|
|
|
|
case M_SOF14:
|
|
|
|
case M_SOF15:
|
|
|
|
if (result == NULL) {
|
|
|
|
/* handle SOFn block */
|
2001-08-12 01:03:37 +08:00
|
|
|
result = (struct gfxinfo *) ecalloc(1, sizeof(struct gfxinfo));
|
2001-05-04 05:28:26 +08:00
|
|
|
FP_FREAD(tmp, sizeof(tmp), socketd, fp, issock);
|
2001-08-12 01:03:37 +08:00
|
|
|
result->bits = FP_FGETC(socketd, fp, issock);
|
2001-04-20 23:37:55 +08:00
|
|
|
FP_FREAD(a, sizeof(a), socketd, fp, issock);
|
2001-01-20 00:52:40 +08:00
|
|
|
result->height = (((unsigned short) a[ 0 ]) << 8) + ((unsigned short) a[ 1 ]);
|
|
|
|
result->width = (((unsigned short) a[ 2 ]) << 8) + ((unsigned short) a[ 3 ]);
|
2001-08-12 01:03:37 +08:00
|
|
|
result->channels = FP_FGETC(socketd, fp, issock);
|
2001-05-04 05:28:26 +08:00
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (! info) /* if we don't want an extanded info -> return */
|
|
|
|
return result;
|
|
|
|
} else {
|
2001-08-12 01:03:37 +08:00
|
|
|
php_skip_variable(socketd, fp, issock);
|
1999-09-02 19:58:23 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case M_APP0:
|
|
|
|
case M_APP1:
|
|
|
|
case M_APP2:
|
|
|
|
case M_APP3:
|
|
|
|
case M_APP4:
|
|
|
|
case M_APP5:
|
|
|
|
case M_APP6:
|
|
|
|
case M_APP7:
|
|
|
|
case M_APP8:
|
|
|
|
case M_APP9:
|
|
|
|
case M_APP10:
|
|
|
|
case M_APP11:
|
|
|
|
case M_APP12:
|
|
|
|
case M_APP13:
|
|
|
|
case M_APP14:
|
|
|
|
case M_APP15:
|
2001-05-04 05:28:26 +08:00
|
|
|
if (info) {
|
2001-08-12 01:03:37 +08:00
|
|
|
php_read_APP(socketd, fp, issock, marker, info); /* read all the app markes... */
|
1999-04-17 08:37:12 +08:00
|
|
|
} else {
|
2001-08-12 01:03:37 +08:00
|
|
|
php_skip_variable(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case M_SOS:
|
|
|
|
case M_EOI:
|
|
|
|
return result; /* we're about to hit image data, or are at EOF. stop processing. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-08-12 01:03:37 +08:00
|
|
|
php_skip_variable(socketd, fp, issock); /* anything else isn't interesting */
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-06-06 21:06:12 +08:00
|
|
|
/* }}} */
|
1999-04-17 08:37:12 +08:00
|
|
|
|
|
|
|
/* main function */
|
2000-05-18 03:48:43 +08:00
|
|
|
|
|
|
|
/* {{{ proto array getimagesize(string imagefile [, array info])
|
|
|
|
Get the size of an image as 4-element array */
|
1999-05-16 19:19:26 +08:00
|
|
|
PHP_FUNCTION(getimagesize)
|
1999-04-17 08:37:12 +08:00
|
|
|
{
|
2001-09-04 14:08:42 +08:00
|
|
|
zval **arg1, **info = NULL;
|
1999-04-17 08:37:12 +08:00
|
|
|
FILE *fp;
|
2001-01-20 00:52:40 +08:00
|
|
|
int issock=0, socketd=0, rsrc_id;
|
|
|
|
int itype = 0;
|
|
|
|
char filetype[8];
|
1999-04-17 08:37:12 +08:00
|
|
|
char temp[64];
|
|
|
|
struct gfxinfo *result = NULL;
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2001-04-20 23:37:55 +08:00
|
|
|
switch(ZEND_NUM_ARGS()) {
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
case 1:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(1, &arg1) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-12-14 11:48:46 +08:00
|
|
|
convert_to_string_ex(arg1);
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
1999-12-19 06:40:35 +08:00
|
|
|
if (zend_get_parameters_ex(2, &arg1, &info) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
}
|
1999-12-14 11:48:46 +08:00
|
|
|
zval_dtor(*info);
|
1999-09-02 19:58:23 +08:00
|
|
|
|
1999-12-14 11:48:46 +08:00
|
|
|
if (array_init(*info) == FAILURE) {
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1999-12-14 11:48:46 +08:00
|
|
|
convert_to_string_ex(arg1);
|
1999-04-17 08:37:12 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WRONG_PARAM_COUNT;
|
|
|
|
break;
|
|
|
|
}
|
2001-05-04 05:28:26 +08:00
|
|
|
|
2001-07-31 15:09:49 +08:00
|
|
|
fp = php_fopen_wrapper(Z_STRVAL_PP(arg1), "rb", IGNORE_PATH|ENFORCE_SAFE_MODE, &issock, &socketd, NULL TSRMLS_CC);
|
2001-01-20 00:52:40 +08:00
|
|
|
|
|
|
|
if (!fp && !socketd) {
|
|
|
|
if (issock != BAD_URL) {
|
|
|
|
char *tmp = estrndup(Z_STRVAL_PP(arg1), Z_STRLEN_PP(arg1));
|
|
|
|
php_strip_url_passwd(tmp);
|
2001-08-12 01:03:37 +08:00
|
|
|
php_error(E_WARNING, "getimagesize: Unable to open '%s' for reading.", tmp);
|
2001-01-20 00:52:40 +08:00
|
|
|
efree(tmp);
|
|
|
|
}
|
|
|
|
RETURN_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (issock) {
|
|
|
|
int *sock=emalloc(sizeof(int));
|
|
|
|
*sock = socketd;
|
2001-08-12 01:03:37 +08:00
|
|
|
rsrc_id = ZEND_REGISTER_RESOURCE(NULL, sock, php_file_le_socket());
|
2001-01-20 00:52:40 +08:00
|
|
|
} else {
|
2001-08-12 01:03:37 +08:00
|
|
|
rsrc_id = ZEND_REGISTER_RESOURCE(NULL, fp, php_file_le_fopen());
|
2001-01-20 00:52:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if((FP_FREAD(filetype, 3, socketd, fp, issock)) <= 0) {
|
2001-08-12 01:03:37 +08:00
|
|
|
php_error(E_WARNING, "getimagesize: Read error!");
|
2001-01-20 00:52:40 +08:00
|
|
|
RETURN_FALSE;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-01-20 00:52:40 +08:00
|
|
|
|
1999-12-18 12:01:20 +08:00
|
|
|
if (!memcmp(filetype, php_sig_gif, 3)) {
|
2001-01-20 00:52:40 +08:00
|
|
|
result = php_handle_gif (socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
itype = 1;
|
1999-12-18 12:01:20 +08:00
|
|
|
} else if (!memcmp(filetype, php_sig_jpg, 3)) {
|
1999-12-14 12:32:54 +08:00
|
|
|
if (info) {
|
2001-01-20 00:52:40 +08:00
|
|
|
result = php_handle_jpeg(socketd, fp, issock, *info);
|
1999-12-14 12:32:54 +08:00
|
|
|
} else {
|
2001-01-20 00:52:40 +08:00
|
|
|
result = php_handle_jpeg(socketd, fp, issock, NULL);
|
1999-12-14 12:32:54 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
itype = 2;
|
1999-12-18 12:01:20 +08:00
|
|
|
} else if (!memcmp(filetype, php_sig_png, 3)) {
|
2001-01-20 00:52:40 +08:00
|
|
|
FP_FREAD(filetype+3, 5, socketd, fp, issock);
|
|
|
|
if (!memcmp(filetype, php_sig_png, 8)) {
|
|
|
|
result = php_handle_png(socketd, fp, issock);
|
1999-04-17 08:37:12 +08:00
|
|
|
itype = 3;
|
|
|
|
} else {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_WARNING, "PNG file corrupted by ASCII conversion");
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2000-06-05 02:29:15 +08:00
|
|
|
} else if (!memcmp(filetype, php_sig_swf, 3)) {
|
2001-01-20 00:52:40 +08:00
|
|
|
result = php_handle_swf(socketd, fp, issock);
|
2000-06-05 02:29:15 +08:00
|
|
|
itype = 4;
|
2001-05-04 05:28:26 +08:00
|
|
|
} else if (!memcmp(filetype, php_sig_psd, 3)) {
|
|
|
|
result = php_handle_psd(socketd, fp, issock);
|
|
|
|
itype = 5;
|
|
|
|
} else if (!memcmp(filetype, php_sig_bmp, 2)) {
|
|
|
|
result = php_handle_bmp(socketd, fp, issock);
|
|
|
|
itype = 6;
|
1999-04-17 08:37:12 +08:00
|
|
|
}
|
2001-01-20 00:52:40 +08:00
|
|
|
|
|
|
|
zend_list_delete(rsrc_id);
|
|
|
|
|
1999-04-17 08:37:12 +08:00
|
|
|
if (result) {
|
|
|
|
if (array_init(return_value) == FAILURE) {
|
1999-08-03 03:17:14 +08:00
|
|
|
php_error(E_ERROR, "Unable to initialize array");
|
2000-07-01 20:23:09 +08:00
|
|
|
efree(result);
|
1999-04-17 08:37:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
add_index_long(return_value, 0, result->width);
|
|
|
|
add_index_long(return_value, 1, result->height);
|
|
|
|
add_index_long(return_value, 2, itype);
|
|
|
|
sprintf(temp, "width=\"%d\" height=\"%d\"", result->width, result->height); /* safe */
|
|
|
|
add_index_string(return_value, 3, temp, 1);
|
1999-09-02 19:58:23 +08:00
|
|
|
|
|
|
|
if (result->bits != 0) {
|
2001-08-12 01:03:37 +08:00
|
|
|
add_assoc_long(return_value, "bits", result->bits);
|
1999-09-02 19:58:23 +08:00
|
|
|
}
|
|
|
|
if (result->channels != 0) {
|
2001-08-12 01:03:37 +08:00
|
|
|
add_assoc_long(return_value, "channels", result->channels);
|
2001-05-04 05:28:26 +08:00
|
|
|
}
|
1999-04-17 08:37:12 +08:00
|
|
|
efree(result);
|
|
|
|
}
|
|
|
|
}
|
2000-05-18 03:40:10 +08:00
|
|
|
/* }}} */
|
2001-06-05 21:12:10 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Local variables:
|
|
|
|
* tab-width: 4
|
|
|
|
* c-basic-offset: 4
|
|
|
|
* End:
|
2001-09-09 21:29:31 +08:00
|
|
|
* vim600: sw=4 ts=4 fdm=marker
|
|
|
|
* vim<600: sw=4 ts=4
|
2001-06-05 21:12:10 +08:00
|
|
|
*/
|