Skip to content

Stdlib: getimagesize() / getimagesizefromstring() — image metadata (ext/standard/image.c parity) #3271

Closed

Description

@PurHur

Category

stdlib

Problem

Zend exposes getimagesize() and getimagesizefromstring() to read width/height/type/mime from image bytes. PurHur/php-compiler has no builtins; both return function_exists(...) === false under bin/vm.php.

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "
\$png = base64_decode(\"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==\");
\$path = sys_get_temp_dir() . \"/phpc-img.png\";
file_put_contents(\$path, \$png);
var_export(getimagesize(\$path));
echo PHP_EOL;
var_export(getimagesizefromstring(\$png));
echo PHP_EOL;
@unlink(\$path);
"
php bin/vm.php -r "var_export(function_exists(\"getimagesize\")); echo PHP_EOL;"
'
Runtime Result
Zend Two arrays: [0]=>1, [1]=>1, 'mime'=>'image/png', …
VM false for function_exists('getimagesize')

Scope (this repo)

Area Files
VM new ext/standard/getimagesize.php, getimagesizefromstring.php (v1: delegate to host GD/fileinfo when available)
Registration ext/standard/Module.php
Tests test/compliance/cases/stdlib/getimagesize_png.phpt
Matrix script/capability-matrix.php

Document host extension dependency in issue/notes if GD unavailable in Docker image.

Done when

  • getimagesize($path) returns Zend-compatible array for 1×1 PNG repro
  • getimagesizefromstring($bytes) same metadata
  • Optional $imageinfo by-ref array populated like Zend
  • ./script/ci-fast.sh --filter getimagesize green

Related

  • Maintainer probe 2026-05-29: both functions missing on VM

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on May 29, 2026
  2. PurHur commented on Jun 12, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 12, 2026

    @PurHur
    OwnerAuthor

    Merged via #8239.

    Implementation: Native byte-header parser in ext/standard/VmImage.php (PNG/GIF/JPEG/BMP/WebP); JIT/AOT via GetimagesizeJitHelper compile hook (PHP-in-PHP, no host GD, no new C runtime). php-src ref: ext/standard/image.c.

    Verification:

    • Issue repro: VM output matches Zend PHP 8.x for 1×1 PNG (getimagesize + getimagesizefromstring)
    • vendor/bin/phpunit --filter getimagesize → OK (6 tests)
    • php bin/compile.php -l test/repro/aot_getimagesize_3271.php → lint_exit:0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions