473,287 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Extract image dimensions (height, width) from Base64 String?

Greetings.

I have managed to stitch together an awesome method of posting text
along with an image to a database, in a way that allows an unlimited
number of previews to ensure that text and image are perfect before
submission. This involves converting any uploaded image to a Base64
String and holding that in a hidden form field until either the post
gets submitted to the database or the image gets replaced with another one.

I have just one question. It is really easy to determine the image’s
dimensions during the initial “preview” (before it is converted to
Base64), but the data naturally gets lost on subsequent previews if the
only thing getting passed along is the Base64 string containing the
image data.

I was wondering if there was some way I could parse the Base64 String to
determine the dimensions of the image, or do I have to take the much
more messy way of including hidden form fields to hold the values?

TIA
...Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #1
7 7813
You need to 'unbundle' your Base64 encoded string and then get the required
property information from the resultant Image object.
"Neo Geshel" <go****@geshel.org> wrote in message
news:50VJf.42395$H%4.32969@pd7tw2no...
Greetings.

I have managed to stitch together an awesome method of posting text
along with an image to a database, in a way that allows an unlimited
number of previews to ensure that text and image are perfect before
submission. This involves converting any uploaded image to a Base64
String and holding that in a hidden form field until either the post
gets submitted to the database or the image gets replaced with another one.

I have just one question. It is really easy to determine the image’s
dimensions during the initial “preview” (before it is converted to
Base64), but the data naturally gets lost on subsequent previews if the
only thing getting passed along is the Base64 string containing the
image data.

I was wondering if there was some way I could parse the Base64 String to
determine the dimensions of the image, or do I have to take the much
more messy way of including hidden form fields to hold the values?

TIA
....Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #2
Stephany Young wrote:
You need to 'unbundle' your Base64 encoded string and then get the required
property information from the resultant Image object.


I kind of figured as much, but do you have an example (after the
unbundling... I know how to do that) that I could use?

TIA
...Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #3
I got the impression that you already had that side of things working...

Just intercept the Image object before you pass it to the 'preview'.
"Neo Geshel" <go****@geshel.org> wrote in message
news:x3WJf.42855$H%4.27931@pd7tw2no...
Stephany Young wrote:
You need to 'unbundle' your Base64 encoded string and then get the
required property information from the resultant Image object.


I kind of figured as much, but do you have an example (after the
unbundling... I know how to do that) that I could use?

TIA
....Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #4
Stephany Young wrote:
I got the impression that you already had that side of things working...

Just intercept the Image object before you pass it to the 'preview'.


Well, the image, encoded as Base64, is embedded directly into the
preview image. That is, it is as such:

<img src="data:image/gif;base64,[image data encoded in base64]" />

And there is a corresponding hidden input field that contains the image
data, also encoded as base64. That way, the img shows the preview, and
the input carries the previewed image data to the next preview. However,
while I am able to convert the image data *from* Base64, I don’t know
what to do with it from there, in terms of parsing it for the height and
width data.

TIA
...Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #5
Oh I see ... You're using HTML.

I was under the impression you were using VB.NET.
"Neo Geshel" <go****@geshel.org> wrote in message
news:IXWJf.44546$B94.2438@pd7tw3no...
Stephany Young wrote:
I got the impression that you already had that side of things working...

Just intercept the Image object before you pass it to the 'preview'.


Well, the image, encoded as Base64, is embedded directly into the
preview image. That is, it is as such:

<img src="data:image/gif;base64,[image data encoded in base64]" />

And there is a corresponding hidden input field that contains the image
data, also encoded as base64. That way, the img shows the preview, and
the input carries the previewed image data to the next preview. However,
while I am able to convert the image data *from* Base64, I don’t know
what to do with it from there, in terms of parsing it for the height and
width data.

TIA
....Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #6
Stephany Young wrote:
Oh I see ... You're using HTML.

I was under the impression you were using VB.NET.


Okay, smartass. Tell me, then, how does one take an image via a file
upload, provide it to the user in a preview (without using a database
*OR* the server file system) through (potentially) multiple previews,
and then finally input it into a database once the preview is accepted
(and only once it is accepted)?

I am using ASP.NET. VB.NET is used in ASP.NET, no? At least, that is the
impression I have been labouring under for the past year or two.

I take the image that the user uploads via the file upload, convert it
into Base64, and then place it into both the image and a hidden input.
The image is for the preview, the hidden input is so the image (now
encoded as Base64) is carried through multiple previews (as the user
refines the text used in the post). Since the <input type="file"
runat="server" /> is completely unlinked from the viewstate, there has
to be some way of carrying any image that was specified through several
previews, and I use the hidden form field for just this purpose. Once
the text (and the choice of image) is satisfactory to the user, they
submit the post, and both the text and the image ends up in a database.

The only way to provide both text *and* image through multiple potential
previews is to convert the image into Base64, and “shoehorn” it inline
with the HTML itself, as a part of the <img> tag (for preview purposes)
and as the content of a hidden <input> tag (for preservation purposes).

Since the <input type="file" runat="server" /> is completely
unassociated with the viewstate, it can only provide the image for a
single preview. Any subsequent previews (prior to a database submission)
cause the image to be lost because it wasn’t saved anywhere. My method
allows me to bypass that problem by preserving the image in a hidden
form field.

My problem is that I can convert the to Base64 (so it is preserved
through more than one preview). I can unconvert it from Base64. I just
am unsure how to extract height and width information from the resulting
code after it has been converted back.

...Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #7
So, we are supposed to know what you are using from one line of vanilla HTML
that you supply:

<quote>
<img src="data:image/gif;base64,[image data encoded in base64]" />
</quote>

Yeah right!!!!

You have said yourself that you take an image and convert it into Base64.

Presumably, you convert the Image object into some form of byte array just
before you Base64 encode it, possibly via a MemoryStream object.

If you do the reverse of the above on the Base64 encoded value that you are
passing around, to the point that you have an Image object, you can get the
dimensions of the graphic and do with them what you will.
"Neo Geshel" <go****@geshel.org> wrote in message
news:xqYJf.45259$B94.7746@pd7tw3no...
Stephany Young wrote:
Oh I see ... You're using HTML.

I was under the impression you were using VB.NET.


Okay, smartass. Tell me, then, how does one take an image via a file
upload, provide it to the user in a preview (without using a database
*OR* the server file system) through (potentially) multiple previews,
and then finally input it into a database once the preview is accepted
(and only once it is accepted)?

I am using ASP.NET. VB.NET is used in ASP.NET, no? At least, that is the
impression I have been labouring under for the past year or two.

I take the image that the user uploads via the file upload, convert it
into Base64, and then place it into both the image and a hidden input.
The image is for the preview, the hidden input is so the image (now
encoded as Base64) is carried through multiple previews (as the user
refines the text used in the post). Since the <input type="file"
runat="server" /> is completely unlinked from the viewstate, there has
to be some way of carrying any image that was specified through several
previews, and I use the hidden form field for just this purpose. Once
the text (and the choice of image) is satisfactory to the user, they
submit the post, and both the text and the image ends up in a database.

The only way to provide both text *and* image through multiple potential
previews is to convert the image into Base64, and “shoehorn” it inline
with the HTML itself, as a part of the <img> tag (for preview purposes)
and as the content of a hidden <input> tag (for preservation purposes).

Since the <input type="file" runat="server" /> is completely
unassociated with the viewstate, it can only provide the image for a
single preview. Any subsequent previews (prior to a database submission)
cause the image to be lost because it wasn’t saved anywhere. My method
allows me to bypass that problem by preserving the image in a hidden
form field.

My problem is that I can convert the to Base64 (so it is preserved
through more than one preview). I can unconvert it from Base64. I just
am unsure how to extract height and width information from the resulting
code after it has been converted back.

....Geshel
--
************************************************** *********************
* My reply-to is an automatically monitored spam honeypot. Do not use *
* it unless you want to be blacklisted by SpamCop. Please reply to my *
* first name at my last name dot org. *
************************************************** *********************
“Anyone who believes in Intelligent Design (“creationism”) is just as
ignorant and ill-educated as someone who believes that the world is
flat, that the Sun circles the Earth or that there really is a tooth
fairy. Darwinism has an overwhelming foundation of evidence that can be
tested and reproduced. Intelligent Design, on the other hand, has no
evidence at all; not one single shred of testable proof. As such,
Intelligent Design is Religious Mythology, and has no right whatsoever
to be in our Science classrooms.” - 99.99+% of Scientists
************************************************** *********************
Mignon McLaughlin once said that “A nymphomaniac is a woman [who is] as
obsessed with sex as the average man.” Unfortunately, since true
nymphomaniacs are so rare, this means that it takes an extraordinary
woman to keep up with an ordinary man.
************************************************** *********************
Feb 19 '06 #8

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...
2
by: Eric McDaniel | last post by:
I am trying to read in a bunch of images and manipulate them using Image::Magick, then display them using Tk::Photo. I would like to do this without creating a temp file for each image, since there...
8
by: Abs | last post by:
Hi! I have an image inside a DIV box with its dimensions specified. The problem is that I don't know the dimensions of the image beforehand, therefore the image grows outside the box if it's...
1
by: Antonie C Malan Snr | last post by:
Dear All, I tried posting this before, but it seems to have disappeared. I need to check image sizes before the user uploads them. This works in the Mozilla family on second and subsequent...
14
by: D. Alvarado | last post by:
Hello, I am trying to open a window containing an image and I would like the image to be flush against the window -- i.e. have no padding or border. Can I make this happen with a single call to a...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
0
by: Neo Geshel | last post by:
Greetings. I have managed to stitch together an awesome method of posting text along with an image to a database, in a way that allows an unlimited number of previews to ensure that text and...
4
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. ...
0
by: wizardworkz | last post by:
Hello All! Having a bit of a problem combining php with javascript here. What I have is a store with images (There will be a smaller image of each item, and a larger image of each item, but I want...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...

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.