473,805 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(
"iVBORw0KGgoAAA ANSUhEUgAAABAAA AAWCAMAAAD+dOxO AAAAB3".
"RJTUUH0gkQEysK Ru4rNAAAAAlwSFl zAAALEgAACxIB0t 1+/AAA".
"AARnQU1BAACxjw v8YQUAAAAJUExUR QAAAP//AAAzM+Z4gaYAAA" .
"AoSURBVHjaY2DA AExMDIyMUARkYxH AABAJCAKysQgMnB ZkhEVg".
"QBwGAJlmANH7wb aHAAAAAElFTkSuQ mCC".
"");
}

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 7929


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.Conten tType = '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
HTMLImageElemen t which expects image data.
Also, how would I call this javascript function
in the img tag?


Some browsers support
<img src="javascript :functionToRetu rnImageData()" 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
9565
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 generic solution. Thanks, Csaba Gabor from New York
14
2524
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 change its text contents from a link elsewhere in the page? I have a rought idea that I'll need something like 'id' in my <td> tags but while I have a greater understanding of server-side programming langauges like PHP, javascript is still very new...
4
6318
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 help Fabian
2
2053
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" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <meta http-equiv="scanner" content="Disabled">
1
4767
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 way to do this is to change the style of this control at runtime ("Left:xx px; Top:xx px"). Another way is to move the HtmlTable in the control (i.e. change the style of it). However I couldn't figure out how to let it work. At design time, I...
1
2151
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 might need to change the Content of this MetaTag. How can I do this?
4
3141
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 know I can create a new master page, but I'd like to just change the master page from the content page if possible. thanks!
0
1999
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: https://www.gotomeeting.com/register/952419737 In this interactive online event, you the participants, and content management strategist Scott Abel, will be interviewing Career and
1
1558
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 - Content Content - Content Content - Content
0
4358
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 "Promena". I change content of property "Promena" from "Origin text" to "Changed text" using thread but content of label is still the same - databinding isn´t working according to my vision. Does somebody know, please, why content of label doesn´t change...
0
9718
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
9596
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
10614
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
10363
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
10109
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...
1
7649
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
5544
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...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3847
muto222
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.