473,394 Members | 1,737 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,394 software developers and data experts.

Change content-type

I need to write a function to return an image that
has been base64 encoded into a string.
This is how it is done in PHP and I need to know
how I can do the same in javascript:

function img_65()
{
header("Content-type: image/png");
header("Content-length: 174");
echo base64_decode(
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAWCAMAAAD+dOxOAAAAB 3".
"RJTUUH0gkQEysKRu4rNAAAAAlwSFlzAAALEgAACxIB0t1 +/AAA".
"AARnQU1BAACxjwv8YQUAAAAJUExURQAAAP//AAAzM+Z4gaYAAA".
"AoSURBVHjaY2DAAExMDIyMUARkYxHAABAJCAKysQgMnBZkhEV g".
"QBwGAJlmANH7wbaHAAAAAElFTkSuQmCC".
"");
}

Here is how I call it in my PHP code:

<?
$img = $_GET["img"];
switch($img)
{
case "65":
img_65();
break;
}
?>
In my HTML, I do this:

<img src="digits.php?img=65" />
I have javascript base64 decode functions so I just
need to know how to change the content-type like
in img_65 function above above in javascript.

Also, how would I call this javascript function
in the img tag?

Jul 23 '05 #1
1 7908


Mr.Clean wrote:
I need to write a function to return an image that
has been base64 encoded into a string. Here is how I call it in my PHP code:

<?
$img = $_GET["img"];
switch($img)
{
case "65":
img_65();
break;
}
?>
In my HTML, I do this:

<img src="digits.php?img=65" />
I have javascript base64 decode functions so I just
need to know how to change the content-type like
in img_65 function above above in javascript.
Where do you want to use Javascript, on the server instead of PHP? Then
it depends on the environment, in ASP you would need to set
Response.ContentType = 'image/png';
With client-side JavaScript you can't change a HTTP response header
obviously but you are dealing with specialized host objects like an
HTMLImageElement which expects image data.
Also, how would I call this javascript function
in the img tag?


Some browsers support
<img src="javascript:functionToReturnImageData()" alt="">
but don't rely on that, see
<http://www.elf.org/pnglets/>
<http://www.elf.org/essay/inline-image.html>
Browser support for such stuff has not improved.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

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

Similar topics

6
by: Csaba2000 | last post by:
How do I detect when the font size has been changed (especially by user action: either Ctrl+Scroll wheel or View/Text Size)? This is just for use on IE 5.5+, but it would be great if there was a...
14
by: Reply Via Newsgroup | last post by:
Folks, Say I have a table, ten columns, ten rows - Each with a word in it. I want to change the values of some/all of the cells in the table via a hyperlink. How do I reference each cell and...
4
by: Fabian | last post by:
Hi I want to change the content of text file. I use an StreamReader to read but I canīt use a StreamWriter for the same Stream. What I must do to implement content changing? Thanks for...
2
by: Jennyfer J Barco | last post by:
Hello, I have the following: <HEAD id="ENGINE"> <title>WebBase.NET Engine</title> <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"> <meta content="Visual Basic 7.0"...
1
by: Leo | last post by:
I created a user control which is some text contained in a HtmlTable. I put this control into main form. I would like to have the ability to move this control around in the main form. I think one...
1
by: Miguel Dias Moura | last post by:
Hello, I am adding a MetaTag from my .pasx.vb code: Dim metaTag As New HtmlMeta() metaTag.Name = "Title" metaTag.Content = "My Web Site" Page.Header.Controls.Add(metaTag) Later in my code I...
4
by: David Lozzi | last post by:
Howdy, I have my master page, and I would like to change the background CSS class per the content page. Only the home page has a different background style, all other pages are using the same. I...
0
by: Scott Abel | last post by:
Tuesday, December 12, 2006 -- 10:00AM EST / 3:00 PM GMT X-Pubs presents: CMS & Change - Love it, Hate it, Master it (Scott Abel & Emma Hamer) Reserve your Webinar seat now at:...
1
by: st12iker | last post by:
I have a datafile with the following format from which I need to extract parts of the text and copy to a seperate file : Header (line 1) --------------------------- (line 2starts) Content -...
0
by: Czechtim | last post by:
Hello, I have problem with databinding. I created small application using structure that I need to demonstrate problem. I need to change content of label when changing content of property...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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...
0
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...
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...

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.