Hi,

I'm new with ImageMagick, so stuck with one problem.
I need IM Identify function to get image size, and it works sweet.
But it need attribute to be filename. And for particular reason i have picture in variable as binary data (I can't avoid it).
With GD there was not problems because ImageCreateFromString make image resource. But now I need IM because new versions of GD don't support GIF.

So, this code works nice:

<?php
$commandIM = "identify image.jpg";
exec ($commandIM, $output, $result);
print_r ($output);
?>

But how to make it work from binary dana, not filename ? This is not working because IM Identify works with file directly:

<?php
$filename = "image.jpg";
$fd = fopen ($filename, "r");
$contents = fread ($fd, filesize ($filename));
fclose ($fd);
exec ($contents, $output, $result);
print_r ($output);
?>

Ofcourse I can save temporary filename and then get with IM and delete, but want avoid that slow-down if there is other ways.
:glare:
Thanks,
Boris

    Actually GIF is working in the new versions. It was restored in GD last year.

      Huh, didn't know that 😃 Thanks

      But any idea how to make this in IM ?

        Well then you actually have to do it that way that you said:

        $tempfn = tempnam("/tmp","");
        $temp = fopen($tempfn, "w");
        fwrite($temp, $binarydata);
        fclose($temp);
        
        $commandIM = "identify $tempfn";
        exec ($commandIM, $output, $result);
        print_r ($output);
        
        unlink($tempfn);
        

        Ofcourse it slows down a little bit:

        PHP

        time php im.php
        Array
        (
        [0] => /tmp/VRjxit JPEG 400x56 DirectClass 7kb 0.000u 0:01
        )

        real 0m0.081s
        user 0m0.044s
        sys 0m0.034s

        DIRECT

        time identify picture.jpg
        picture.jpg JPEG 400x56 DirectClass 7kb 0.000u 0:01

        real 0m0.032s
        user 0m0.015s
        sys 0m0.016s

          Write a Reply...