get image size from binary data

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christoph Burschka

    get image size from binary data

    Is there some way to get the dimensions of an image, given the binary
    data of the image, without having to write it to a temporary file?

    It seems that getimagesize() will only take a filename, but since I have
    to download the image from a remote URL with fsockopen(), I have it
    stored as a binary string.

    I've had a cursory glance at the data, but predictably the size is not
    stored in decimal format anywhere...

    --
    cb

  • james.gauth@googlemail.com

    #2
    Re: get image size from binary data

    On 26 Jun, 08:31, Christoph Burschka <christoph.burs c...@rwth-
    aachen.dewrote:
    Is there some way to get the dimensions of an image, given the binary
    data of the image, without having to write it to a temporary file?
    >
    It seems that getimagesize() will only take a filename, but since I have
    to download the image from a remote URL with fsockopen(), I have it
    stored as a binary string.
    >
    I've had a cursory glance at the data, but predictably the size is not
    stored in decimal format anywhere...
    >
    --
    cb
    If the image format is supported by your GD Library, you can use the
    following:

    <?php

    $binary_data = file_get_conten ts('http://www.google.co.u k/intl/en_uk/
    images/logo.gif');

    $im = imagecreatefrom string($binary_ data);

    $width = imagesx($im);
    $height = imagesy($im);

    print "width: $width\n";
    print "height: $height\n";

    ?>

    Comment

    • Armand Brahaj

      #3
      Re: get image size from binary data

      james.gauth@goo glemail.com wrote:
      On 26 Jun, 08:31, Christoph Burschka <christoph.burs c...@rwth-
      aachen.dewrote:
      >Is there some way to get the dimensions of an image, given the binary
      >data of the image, without having to write it to a temporary file?
      >>
      >It seems that getimagesize() will only take a filename, but since I have
      >to download the image from a remote URL with fsockopen(), I have it
      >stored as a binary string.
      >>
      >I've had a cursory glance at the data, but predictably the size is not
      >stored in decimal format anywhere...
      >>
      >--
      >cb
      >
      If the image format is supported by your GD Library, you can use the
      following:
      >
      <?php
      >
      $binary_data = file_get_conten ts('http://www.google.co.u k/intl/en_uk/
      images/logo.gif');
      >
      $im = imagecreatefrom string($binary_ data);
      >
      $width = imagesx($im);
      $height = imagesy($im);
      >
      print "width: $width\n";
      print "height: $height\n";
      >
      ?>
      >
      Someone correct me if I am wrong, but whenever you open an image/file to
      read (even if you want to read the headers) you are storing it to some
      temporary buffer/space on your machine!
      Maybe the GD solution above is the best!

      Armand

      Comment

      • Christoph Burschka

        #4
        Re: get image size from binary data

        Armand Brahaj wrote:
        james.gauth@goo glemail.com wrote:
        >On 26 Jun, 08:31, Christoph Burschka <christoph.burs c...@rwth-
        >aachen.dewrote :
        >>Is there some way to get the dimensions of an image, given the binary
        >>data of the image, without having to write it to a temporary file?
        >>>
        >>It seems that getimagesize() will only take a filename, but since I have
        >>to download the image from a remote URL with fsockopen(), I have it
        >>stored as a binary string.
        >>>
        >>I've had a cursory glance at the data, but predictably the size is not
        >>stored in decimal format anywhere...
        >>>
        >>--
        >>cb
        >>
        >If the image format is supported by your GD Library, you can use the
        >following:
        >>
        ><?php
        >>
        >$binary_data = file_get_conten ts('http://www.google.co.u k/intl/en_uk/
        >images/logo.gif');
        >>
        >$im = imagecreatefrom string($binary_ data);
        >>
        >$width = imagesx($im);
        >$height = imagesy($im);
        >>
        >print "width: $width\n";
        >print "height: $height\n";
        >>
        >?>
        >>
        >
        Someone correct me if I am wrong, but whenever you open an image/file to
        read (even if you want to read the headers) you are storing it to some
        temporary buffer/space on your machine!
        Maybe the GD solution above is the best!
        >
        Armand
        Yeah, so I'd be downloading the image data, saving it to a temporary
        file, reading the temp file into the buffer and getting the header. Not
        exactly efficient.

        Thanks for imagecreatefrom string(); that was exactly the function I was
        looking for!

        --
        cb

        Comment

        Working...