Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can javascript change image brightness/contrast?

Status
Not open for further replies.

133tcamel

Programmer
Sep 22, 2002
137
0
0
IN
Is there any way to change the an IMG brightness/contrast using javascript?

If you're wondering why I need this, its is because I wanted to add this as a function to my IE's context menu ( using which I can decrease and increase the image's brighteness and contrast by right clicking on it and selecting this from the menu..
The best I could do now is to change its alpha value to make it bright, but this is too less than perfect and fails with images on black backgrounds. Not sure if I'm making sense here? ;) If not, please ask and I'll show you a demo of what I'm making (or have been able to make so far)

thanks!
san
 
If you can come up with an HTML-level way of setting an images brightness/contrast, then it is almost certain that you can program JavaScript to tweak it.

The first step is the hardest... The IMG tag seems to have no support whatsoever for image properties such as brightness, contrast, etc.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
If you have an image editing application you can do it there. Mostly all image applications have brightness contrast support.]


[2thumbsup]
Joe

Talent does what it can, genius does what it must
 
Oh. Maybe I misunderstood. Do you want to do it offline, or on-the-fly?

Offline is a complete no-brainer.

I believe on-the-fly would be very difficult.

Cheers,


[monkey] Edward [monkey]

"Cut a hole in the door. Hang a flap. Criminy, why didn't I think of this earlier?!" -- inventor of the cat door
 
yes, I was trying on-the-fly.. so that you can just view those pages and brighten any dark images on-the-fly by just right clicking on it (I often find the need for this as i usually work on a very very dull monitor to prevent my eyes from hurting)

anyway, its very difficult indeed, but nonetheless the alpha thing worked for me. Its a very simple code and can be added to the IE's context menus as shown on this page (( to brighten images without reloading the page or anything

Code:
<HTML>
<SCRIPT LANGUAGE=&quot;javascript&quot;>
var parentwin = external.menuArguments;
parentwin.event.srcElement.style.filter = &quot;alpha(opacity=50)&quot;;
</SCRIPT>
</HTML>

This code fails if the background is not white and isn't very good performance wise either, but since there is nothing else available, i think it'll have to do for now ;)

cheers!
san

P.S>here is a screenshot, to help you understand if I still didn't make sense ;)

Before:
test.gif


After
test1.gif
 
look at ASPImage form serverobjects.com, it's server side but should work for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top