31#if defined(HAVE_ZLIB) && !defined(COMPILE_DL_ZLIB)
43 (char) 0x0d, (
char) 0x0a, (char) 0x1a, (
char) 0x0a};
48 (char)0x6a, (
char)0x50, (char)0x20, (
char)0x20,
49 (char)0x0d, (
char)0x0a, (char)0x87, (
char)0x0a};
81 result->width = (
unsigned int)
dim[0] | (((
unsigned int)
dim[1])<<8);
82 result->height = (
unsigned int)
dim[2] | (((
unsigned int)
dim[3])<<8);
83 result->bits =
dim[4]&0x80 ? ((((
unsigned int)
dim[4])&0x07) + 1) : 0;
103 result->height = (((
unsigned int)
dim[0]) << 24) + (((
unsigned int)
dim[1]) << 16) + (((
unsigned int)
dim[2]) << 8) + ((
unsigned int)
dim[3]);
104 result->width = (((
unsigned int)
dim[4]) << 24) + (((
unsigned int)
dim[5]) << 16) + (((
unsigned int)
dim[6]) << 8) + ((
unsigned int)
dim[7]);
114 unsigned char dim[16];
123 size = (((
unsigned int)
dim[ 3]) << 24) + (((
unsigned int)
dim[ 2]) << 16) + (((
unsigned int)
dim[ 1]) << 8) + ((
unsigned int)
dim[ 0]);
126 result->width = (((
unsigned int)
dim[ 5]) << 8) + ((
unsigned int)
dim[ 4]);
127 result->height = (((
unsigned int)
dim[ 7]) << 8) + ((
unsigned int)
dim[ 6]);
131 result->width = (((
unsigned int)
dim[ 7]) << 24) + (((
unsigned int)
dim[ 6]) << 16) + (((
unsigned int)
dim[ 5]) << 8) + ((
unsigned int)
dim[ 4]);
132 result->height = (((
unsigned int)
dim[11]) << 24) + (((
unsigned int)
dim[10]) << 16) + (((
unsigned int)
dim[ 9]) << 8) + ((
unsigned int)
dim[ 8]);
134 result->bits = (((
unsigned int)
dim[15]) << 8) + ((
unsigned int)
dim[14]);
145static unsigned long int php_swf_get_bits (
unsigned char*
buffer,
unsigned int pos,
unsigned int count)
148 unsigned long int result = 0;
153 ((((
buffer[loop / 8]) >> (7 - (loop % 8))) & 0x01) << (
count - (loop -
pos) - 1));
159#if defined(HAVE_ZLIB) && !defined(COMPILE_DL_ZLIB)
167 unsigned long len=64, szlength;
168 int factor = 1,maxfactor = 16;
183 if (uncompress(b, &
len,
a,
sizeof(
a)) != Z_OK) {
206 szlength =
ZSTR_LEN(bufz) * (1<<factor++);
209 }
while ((
status==Z_BUF_ERROR)&&(factor<maxfactor));
226 bits = php_swf_get_bits (b, 0, 5);
228 php_swf_get_bits (b, 5,
bits)) / 20;
230 php_swf_get_bits (b, 5 + (2 *
bits),
bits)) / 20;
255 bits = php_swf_get_bits (
a, 0, 5);
257 php_swf_get_bits (
a, 5,
bits)) / 20;
259 php_swf_get_bits (
a, 5 + (2 *
bits),
bits)) / 20;
271 unsigned char dim[9];
288 result->width = (((
unsigned int)
dim[0]) << 24) + (((
unsigned int)
dim[1]) << 16) + (((
unsigned int)
dim[2]) << 8) + ((
unsigned int)
dim[3]);
289 result->height = (((
unsigned int)
dim[4]) << 24) + (((
unsigned int)
dim[5]) << 16) + (((
unsigned int)
dim[6]) << 8) + ((
unsigned int)
dim[7]);
332#define M_PSEUDO 0xFFD8
335static unsigned short php_read2(
php_stream * stream)
342 return (((
unsigned short)
a[0]) << 8) + ((
unsigned short)
a[1]);
348static unsigned int php_next_marker(
php_stream * stream,
int last_marker,
int ff_read)
354 size_t extraneous = 0;
373 }
while (marker == 0xff);
378 return (
unsigned int)marker;
384static int php_skip_variable(
php_stream * stream)
386 zend_off_t length = ((
unsigned int)php_read2(stream));
397static size_t php_read_stream_all_chunks(
php_stream *stream,
char *
buffer,
size_t length)
399 size_t read_total = 0;
402 read_total += read_now;
403 if (read_now < stream->chunk_size && read_total != length) {
406 }
while (read_total < length);
412static int php_read_APP(
php_stream * stream,
unsigned int marker,
zval *info)
419 length = php_read2(stream);
427 if (php_read_stream_all_chunks(stream,
buffer, length) != length) {
432 snprintf(markername,
sizeof(markername),
"APP%d", marker -
M_APP0);
436 add_assoc_stringl(info, markername,
buffer, length);
450 unsigned short length, ff_read=1;
453 marker = php_next_marker(stream, marker, ff_read);
472 length = php_read2(stream);
474 result->height = php_read2(stream);
475 result->width = php_read2(stream);
477 if (!info || length < 8) {
484 if (!php_skip_variable(stream)) {
507 if (!php_read_APP(stream, marker, info)) {
511 if (!php_skip_variable(stream)) {
522 if (!php_skip_variable(stream)) {
534static unsigned int php_read4(
php_stream * stream)
541 return (((
unsigned int)
a[0]) << 24)
542 + (((
unsigned int)
a[1]) << 16)
543 + (((
unsigned int)
a[2]) << 8)
544 + (((
unsigned int)
a[3]));
549#define JPEG2000_MARKER_PREFIX 0xFF
550#define JPEG2000_MARKER_SOC 0x4F
551#define JPEG2000_MARKER_SOT 0x90
552#define JPEG2000_MARKER_SOD 0x93
553#define JPEG2000_MARKER_EOC 0xD9
554#define JPEG2000_MARKER_SIZ 0x51
555#define JPEG2000_MARKER_COD 0x52
556#define JPEG2000_MARKER_COC 0x53
557#define JPEG2000_MARKER_RGN 0x5E
558#define JPEG2000_MARKER_QCD 0x5C
559#define JPEG2000_MARKER_QCC 0x5D
560#define JPEG2000_MARKER_POC 0x5F
561#define JPEG2000_MARKER_TLM 0x55
562#define JPEG2000_MARKER_PLM 0x57
563#define JPEG2000_MARKER_PLT 0x58
564#define JPEG2000_MARKER_PPM 0x60
565#define JPEG2000_MARKER_PPT 0x61
566#define JPEG2000_MARKER_SOP 0x91
567#define JPEG2000_MARKER_EPH 0x92
568#define JPEG2000_MARKER_CRG 0x63
569#define JPEG2000_MARKER_COM 0x64
577 int highest_bit_depth, bit_depth;
578 unsigned char first_marker_id;
601 result->width = php_read4(stream);
602 result->height = php_read4(stream);
618 result->channels = php_read2(stream);
625 highest_bit_depth = 0;
626 for (i = 0; i <
result->channels; i++) {
629 if (bit_depth > highest_bit_depth) {
630 highest_bit_depth = bit_depth;
637 result->bits = highest_bit_depth;
648 unsigned int box_length;
649 unsigned int box_type;
650 char jp2c_box_id[] = {(char)0x6a, (
char)0x70, (char)0x32, (
char)0x63};
663 box_length = php_read4(stream);
665 if (
php_stream_read(stream, (
void *)&box_type,
sizeof(box_type)) !=
sizeof(box_type)) {
670 if (box_length == 1) {
675 if (!memcmp(&box_type, jp2c_box_id, 4))
680 result = php_handle_jpc(stream);
685 if ((
int)box_length <= 0) {
704PHPAPI const int php_tiff_bytes_per_format[] = {0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8};
707#define TAG_IMAGEWIDTH 0x0100
708#define TAG_IMAGEHEIGHT 0x0101
710#define TAG_COMP_IMAGEWIDTH 0xA002
711#define TAG_COMP_IMAGEHEIGHT 0xA003
713#define TAG_FMT_BYTE 1
714#define TAG_FMT_STRING 2
715#define TAG_FMT_USHORT 3
716#define TAG_FMT_ULONG 4
717#define TAG_FMT_URATIONAL 5
718#define TAG_FMT_SBYTE 6
719#define TAG_FMT_UNDEFINED 7
720#define TAG_FMT_SSHORT 8
721#define TAG_FMT_SLONG 9
722#define TAG_FMT_SRATIONAL 10
723#define TAG_FMT_SINGLE 11
724#define TAG_FMT_DOUBLE 12
729static int php_ifd_get16u(
void *Short,
int motorola_intel)
731 if (motorola_intel) {
732 return (((
unsigned char *)Short)[0] << 8) | ((
unsigned char *)Short)[1];
734 return (((
unsigned char *)Short)[1] << 8) | ((
unsigned char *)Short)[0];
741static signed short php_ifd_get16s(
void *Short,
int motorola_intel)
743 return (
signed short)php_ifd_get16u(Short, motorola_intel);
749static int php_ifd_get32s(
void *
Long,
int motorola_intel)
751 if (motorola_intel) {
752 return ((
unsigned)(((
unsigned char *)
Long)[0]) << 24) | (((
unsigned char *)
Long)[1] << 16)
753 | (((
unsigned char *)
Long)[2] << 8 ) | (((
unsigned char *)
Long)[3] << 0 );
755 return ((
unsigned)(((
unsigned char *)
Long)[3]) << 24) | (((
unsigned char *)
Long)[2] << 16)
756 | (((
unsigned char *)
Long)[1] << 8 ) | (((
unsigned char *)
Long)[0] << 0 );
763static unsigned php_ifd_get32u(
void *
Long,
int motorola_intel)
765 return (
unsigned)php_ifd_get32s(
Long, motorola_intel) & 0xffffffff;
775 unsigned char *dir_entry;
776 size_t ifd_size, dir_size, entry_value,
width=0,
height=0, ifd_addr;
777 int entry_tag , entry_type;
778 char *ifd_data, ifd_ptr[4];
782 ifd_addr = php_ifd_get32u(ifd_ptr, motorola_intel);
791 num_entries = php_ifd_get16u(ifd_data, motorola_intel);
792 dir_size = 2 +12*num_entries +4;
794 ifd_data =
erealloc(ifd_data,ifd_size);
801 for(i=0;i<num_entries;i++) {
802 dir_entry = (
unsigned char *) ifd_data+2+i*12;
803 entry_tag = php_ifd_get16u(dir_entry+0, motorola_intel);
804 entry_type = php_ifd_get16u(dir_entry+2, motorola_intel);
808 entry_value = (size_t)(dir_entry[8]);
811 entry_value = php_ifd_get16u(dir_entry+8, motorola_intel);
814 entry_value = php_ifd_get16s(dir_entry+8, motorola_intel);
817 entry_value = php_ifd_get32u(dir_entry+8, motorola_intel);
820 entry_value = php_ifd_get32s(dir_entry+8, motorola_intel);
871 chunkId = php_ifd_get32s(
a+0, 1);
872 size = php_ifd_get32s(
a+4, 1);
876 if ((
size & 1) == 1) {
879 if (chunkId == 0x424d4844) {
883 width = php_ifd_get16s(
a+0, 1);
884 height = php_ifd_get16s(
a+2, 1);
964 (*result)->width =
width;
965 (*result)->height =
height;
977 if (!php_get_wbmp(stream, &
result, 0)) {
1003 if (
sscanf(fline,
"#define %s %d", iname, &
value) == 2) {
1035 (*result)->width =
width;
1036 (*result)->height =
height;
1049 php_get_xbm(stream, &
result);
1058 unsigned char dim[16];
1064 num_icons = (((
unsigned int)
dim[1]) << 8) + ((
unsigned int)
dim[0]);
1066 if (num_icons < 1 || num_icons > 255)
1071 while (num_icons > 0)
1076 if ((((
unsigned int)
dim[7]) << 8) + ((
unsigned int)
dim[6]) >=
result->bits)
1080 result->bits = (((
unsigned int)
dim[7]) << 8) + ((
unsigned int)
dim[6]);
1099 const char sig[3] = {
'V',
'P',
'8'};
1100 unsigned char buf[18];
1106 if (memcmp(
buf, sig, 3)) {
1128 result->height = (
buf[10] >> 6) + (
buf[11] << 2) + ((
buf[12] & 0xF) << 10) + 1;
1147static const uint8_t* php_avif_stream_read(
void* stream,
size_t num_bytes) {
1157 return avif_stream->
buffer;
1160static void php_avif_stream_skip(
void*
stream,
size_t num_bytes) {
1219 switch( image_type) {
1223 return "image/jpeg";
1228 return "application/x-shockwave-flash";
1235 return "image/tiff";
1239 return "image/vnd.wap.wbmp";
1241 return "application/octet-stream";
1247 return "image/vnd.microsoft.icon";
1249 return "image/webp";
1251 return "image/avif";
1254 return "application/octet-stream";
1277 const char *imgext =
NULL;
1285 switch (image_type) {
1352 int twelve_bytes_read;
1430 if (!twelve_bytes_read) {
1455 result = php_handle_gif(stream);
1459 result = php_handle_jpeg(stream, info);
1465 result = php_handle_png(stream);
1468 result = php_handle_swf(stream);
1471#if defined(HAVE_ZLIB) && !defined(COMPILE_DL_ZLIB)
1472 result = php_handle_swc(stream);
1474 php_error_docref(
NULL,
E_NOTICE,
"The image is a compressed SWF file, but you do not have a static version of the zlib extension enabled");
1478 result = php_handle_psd(stream);
1481 result = php_handle_bmp(stream);
1490 result = php_handle_jpc(stream);
1493 result = php_handle_jp2(stream);
1496 result = php_handle_iff(stream);
1499 result = php_handle_wbmp(stream);
1502 result = php_handle_xbm(stream);
1505 result = php_handle_ico(stream);
1508 result = php_handle_webp(stream);
1511 result = php_handle_avif(stream);
1530 if (
result->channels != 0) {
1562 info = zend_try_array_init(info);
AvifInfoStatus AvifInfoIdentifyStream(void *stream, read_stream_t read, skip_stream_t skip)
AvifInfoStatus AvifInfoGetFeaturesStream(void *stream, read_stream_t read, skip_stream_t skip, AvifInfoFeatures *features)
#define AVIFINFO_MAX_NUM_READ_BYTES
getimagesizefromstring(string $string, &$image_info=null)
sscanf(string $string, string $format, mixed &... $vars)
strrchr(string $haystack, string $needle, bool $before_needle=false)
count(Countable|array $value, int $mode=COUNT_NORMAL)
image_type_to_mime_type(int $image_type)
getimagesize(string $filename, &$image_info=null)
filetype(string $filename)
image_type_to_extension(int $image_type, bool $include_dot=true)
zend_ffi_ctype_name_buf buf
#define TAG_COMP_IMAGEHEIGHT
PHPAPI const char php_sig_bmp[2]
PHPAPI const char php_sig_tif_ii[4]
PHPAPI const char php_sig_png[8]
bool php_is_image_avif(php_stream *stream)
PHPAPI const char php_sig_psd[4]
PHPAPI const char php_sig_jpc[3]
PHPAPI const char php_sig_gif[3]
PHPAPI const char php_sig_riff[4]
PHPAPI char * php_image_type_to_mime_type(int image_type)
PHPAPI const char php_sig_swc[3]
PHPAPI const char php_sig_jp2[12]
PHPAPI const char php_sig_iff[4]
PHPAPI const char php_sig_tif_mm[4]
#define TAG_COMP_IMAGEWIDTH
#define JPEG2000_MARKER_SIZ
PHPAPI const char php_sig_swf[3]
PHPAPI const char php_sig_jpg[3]
PHPAPI const char php_sig_webp[4]
PHPAPI const char php_sig_ico[4]
PHPAPI int php_getimagetype(php_stream *stream, const char *input, char *filetype)
PHPAPI ZEND_COLD void php_error_docref(const char *docref, int type, const char *format,...)
unsigned const char * pos
#define php_stream_memory_open(mode, str)
#define TEMP_STREAM_READONLY
struct _php_stream php_stream
#define php_stream_read(stream, buf, count)
#define php_stream_gets(stream, buf, maxlen)
#define php_stream_rewind(stream)
#define PHP_STREAM_COPY_ALL
#define php_stream_getc(stream)
#define php_stream_seek(stream, offset, whence)
#define php_stream_eof(stream)
#define php_stream_close(stream)
#define php_stream_copy_to_mem(src, maxlen, persistent)
#define php_stream_open_wrapper(path, mode, options, opened)
uint8_t buffer[AVIFINFO_MAX_NUM_READ_BYTES]
#define INTERNAL_FUNCTION_PARAMETERS
#define INTERNAL_FUNCTION_PARAM_PASSTHRU
ZEND_API void add_index_string(zval *arg, zend_ulong index, const char *str)
ZEND_API ZEND_COLD void zend_argument_value_error(uint32_t arg_num, const char *format,...)
ZEND_API void add_index_long(zval *arg, zend_ulong index, zend_long n)
#define CHECK_NULL_PATH(p, l)
#define ZEND_PARSE_PARAMETERS_END()
#define ZVAL_STRING(z, s)
#define Z_PARAM_STR(dest)
#define ZEND_PARSE_PARAMETERS_START(min_num_args, max_num_args)
#define Z_PARAM_LONG(dest)
#define Z_PARAM_BOOL(dest)
#define Z_PARAM_ZVAL(dest)
#define ecalloc(nmemb, size)
#define erealloc(ptr, size)
strncmp(string $string1, string $string2, int $length)
strcmp(string $string1, string $string2)
zend_string_release_ex(func->internal_function.function_name, 0)
ZEND_API zval *ZEND_FASTCALL zend_hash_str_find(const HashTable *ht, const char *str, size_t len)
#define MAX_LENGTH_OF_LONG
struct _zend_string zend_string
#define Z_ARRVAL_P(zval_p)