PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > alt.comp.lang.php > get image size from binary data
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
get image size from binary data

Réponse
 
LinkBack Outils de la discussion
Vieux 26/06/2007, 08h31   #1
Christoph Burschka
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut 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

  Réponse avec citation
Vieux 26/06/2007, 09h38   #2
james.gauth@googlemail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: get image size from binary data

On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@rwth-
aachen.de> wrote:
> 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_contents('http://www.google.co.uk/intl/en_uk/
images/logo.gif');

$im = imagecreatefromstring($binary_data);

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

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

?>

  Réponse avec citation
Vieux 26/06/2007, 21h50   #3
Armand Brahaj
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: get image size from binary data

james.gauth@googlemail.com wrote:
> On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@rwth-
> aachen.de> wrote:
>> 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_contents('http://www.google.co.uk/intl/en_uk/
> images/logo.gif');
>
> $im = imagecreatefromstring($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
  Réponse avec citation
Vieux 27/06/2007, 09h26   #4
Christoph Burschka
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: get image size from binary data

Armand Brahaj wrote:
> james.gauth@googlemail.com wrote:
>> On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@rwth-
>> aachen.de> wrote:
>>> 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_contents('http://www.google.co.uk/intl/en_uk/
>> images/logo.gif');
>>
>> $im = imagecreatefromstring($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 imagecreatefromstring(); that was exactly the function I was
looking for!

--
cb

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 08h10.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11728 seconds with 12 queries