Send image to applet

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jordan Gomila

    Send image to applet

    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

    #2
    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.b e/img/watched_y.gif"
    width="18" height="18"></p>
    <script language="javas cript">
    if (document.image s) {
    // 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

    Comment

    • Jordan Gomila

      #3
      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.



      Comment

      • Bart Van der Donck

        #4
        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;hei ght:200px;backg round-color: white; }
        </style>
        <script language="javas cript">
        function alterpic(o,c)
        {
        if (document.image s) {
        document.getEle mentById("back" ).style.backgro undColor=c;
        document.images["sImg"].style.filter = "alpha(opacity= "+o+")";
        document.images["sImg"].style.MozOpaci ty=o/100;
        }
        }
        </script>
        </head>
        <body bgcolor="white" >

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

        <p>
        <input type="button"
        onClick="alterp ic('30','red')" value="Version 1">
        <input type="button"
        onClick="alterp ic('80','blue') " value="Version 2">
        <input type="button"
        onClick="alterp ic('40','green' )" value="Version 3">
        <input type="button"
        onClick="alterp ic('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

        Comment

        Working...