473,795 Members | 3,457 Online
Bytes | Software Development & Data Engineering Community
+ 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 12991
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";

?>

Jun 26 '07 #2
ja*********@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
Jun 26 '07 #3
Armand Brahaj wrote:
ja*********@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

Jun 27 '07 #4

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

Similar topics

3
11767
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 table in MySQL with the path & filename to the image. I have successfully uploaded and performed an update query on the database, but the problem I have is I cannot retain the primary key field in a variable which is then used in a SQL update...
7
1754
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 I specify the size ? Thanks Tom
2
2044
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 images and put them in one binary file, but couldn't figure out a way to do that, anyone has an idea? thanks
1
2511
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- John
3
1730
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 as an image in my browser. Is this possible, and how should I do this? thx,
13
2359
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 reached yet (I have gone all the way to page 50 on Google's results!!). Here are my requirements: • I have a DataGrid. Everything will be done from here. Everything. No exceptions. Everything will also be done in VB, without any code-behind to...
5
10635
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 the dataset because I don't know what datatype to set the dataset column and then set this image to. I saw an example where someone defended a datatable in the global class and defined the column as an object, however, when I define a strongly...
2
2813
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"> <form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">
1
11094
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 StringIO objects being passed in place of file objects. StringIO objects are binary strings of variable length that are kept in memory so i saved the image in stringio objects the following code does that for gif image ...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4113
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 we have to send another system

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.