473,472 Members | 2,038 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

Jun 26 '07 #1
3 12915
On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@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_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";

?>

Jun 26 '07 #2
ja*********@googlemail.com wrote:
On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@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_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
Jun 26 '07 #3
Armand Brahaj wrote:
ja*********@googlemail.com wrote:
>On 26 Jun, 08:31, Christoph Burschka <christoph.bursc...@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_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

Jun 27 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: dave | last post by:
Hello there, I am at my wit's end ! I have used the following script succesfully to upload an image to my web space. But what I really want to be able to do is to update an existing record in a...
7
by: Tom | last post by:
hello friends I want to specify a field to save icons I want to give this field a maximum of 120kb for each icon to be stored in the db. what datatype should I assign to this field and how do...
2
by: S.Creek | last post by:
Hi, I need to take few files (images in my case) and create one file out of them, this file should be accessed so i can grab a single image from it if necessary, i thought of taking all the...
1
by: John Thompson | last post by:
We're sooo close. When we load the page to upload the image, all of the prms go through except the binary image data. Using SQL server with the data type set to "image". Please help! Thanks-...
3
by: Kristof Thys | last post by:
Hello, I'm writing a ASP.net webservice wich will visualize an image, generated by another application. The generated image is a char*. I can transform this to a String*, but I want to view it...
13
by: Neo Geshel | last post by:
I have examined about 80+ different upload scripts on the 'net, both in VB and C#, and none seem to do what I need them to do. Perhaps someone here can point me somewhere that Google hasn't...
5
by: moondaddy | last post by:
I'm caching a dataset in an asp.net session variable to hold a user's data. one data item I need to store is an image the user uploaded. My problem is that I don't know how to get the image into...
2
by: amritranjan | last post by:
This is my Jsp code for image upload in database: -----------Upload.jsp---------------- <html> <head> <title>Account Details </title> </head> <body bgproperties="fixed" bgcolor="#CCFFFF">...
1
by: bharathv6 | last post by:
i need to do is modify the image in memory like resizing the image in memory etc ... with out saving it disk as i have to return back the image with out saving it disk PIL supports the use of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.