Connecting Tech Pros Worldwide Forums | Help | Site Map

Send image to applet

Jordan Gomila
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi,

I wish to get the pixels os an image to transform it.

There is any posibility to do this with javascript ?

I have done with java, but I can't load web images from other http servers,
can I send the data of the image to the applet ?



Bart Van der Donck
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Send image to applet


Jordan Gomila wrote:
[color=blue]
> I wish to get the pixels os an image to transform it.
> There is any posibility to do this with javascript ?
> I have done with java, but I can't load web images from
> other http servers, can I send the data of the image to
> the applet ?[/color]

The following code should help you:

<html>
<head></head>
<body>
<p><img name="sImg"
src="http://groups.google.be/img/watched_y.gif"
width="18" height="18"></p>
<script language="javascript">
if (document.images) {
// show initial values of the image
showvalues();
// change width and height of image
document.images["sImg"].width=50;
document.images["sImg"].height=40;
// now read out values again
showvalues();
}
function showvalues() {
w = document.images["sImg"].width;
h = document.images["sImg"].height;
alert("Width is now "+w+" and height is now "+h);
}
</script>
</body>
</html>

--
Bart

Jordan Gomila
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Send image to applet


Thanks, but I am not trying to change width and heigth. I am changing pixel
color.

I have done it with a java applet but I wish to allow to load images from
web, and as it is not allowed with untrusted applets I amb looking for other
alternatives.



Bart Van der Donck
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Send image to applet


Jordan Gomila wrote:
[color=blue]
> Thanks, but I am not trying to change width and
> heigth. I am changing pixel color.
> I have done it with a java applet but I wish to
> allow to load images from web, and as it is not
> allowed with untrusted applets I amb looking for
> other alternatives.[/color]

Client side javascript actually can't *change* image properties. It can
only affect the way they are shown on the user's screen, which is a
significant difference.

It's not very clear to me what you mean by "changing pixel color".
There are some CSS/javascript possibilities that you could use/combine
to alter the image's appearance.

Maybe this could be a start:

<html>
<head>
<style>
div { width:200px;height:200px;background-color: white; }
</style>
<script language="javascript">
function alterpic(o,c)
{
if (document.images) {
document.getElementById("back").style.backgroundCo lor=c;
document.images["sImg"].style.filter = "alpha(opacity="+o+")";
document.images["sImg"].style.MozOpacity=o/100;
}
}
</script>
</head>
<body bgcolor="white">

<p>
<div id="back" name="back"><img name="sImg"
src="http://groups.google.be/img/watched_y.gif"
width="200" height="200"></div>
</p>

<p>
<input type="button"
onClick="alterpic('30','red')" value="Version 1">
<input type="button"
onClick="alterpic('80','blue')" value="Version 2">
<input type="button"
onClick="alterpic('40','green')" value="Version 3">
<input type="button"
onClick="alterpic('100','white')" value="Original">
</p>

</body>
</html>

Please note that you're on sensitive grounds here when it comes to
browser compatibility. I tested the code on latest IE and NS versions -
should be no problem there.

If you want to actually change your image, you should use a server side
approach. E.g. PHP/CGI with a call to GD/ImageMagick on Unix based
operating systems.

--
Bart

Closed Thread