0

Im loocking for some implementation of jquery that I cannot find that fit my requierements.

I need to upload a image from my PC, and be able to change the background colo, as I do (im supposed to use png images with transparent parts).

I could like to be able to add some icons and text over the image I have uploaded at the browser that I can allready manage.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">

    <title>Untitled Document</title>
    <script src=
    "http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js" type=
    "text/javascript"></script>
    <script>
$(document).ready(function() {
        $("#color").change(function(){
            var clr = $(this).val();
            $("#bgcolor").css("background-color",clr);
        });
    });
         function showMyImage(fileInput) {
            var files = fileInput.files;
            for (var i = 0; i < files.length; i++) {           
                var file = files[i];
                var imageType = /image.*/;     
                if (!file.type.match(imageType)) {
                    continue;
                }           
                var img=document.getElementById("thumbnil");            
                img.file = file;    
                var reader = new FileReader();
                reader.onload = (function(aImg) { 
                    return function(e) { 
                        aImg.src = e.target.result; 
                    }; 
                })(img);
                reader.readAsDataURL(file);
            }    
        }
    </script>
    <style type="text/css">
.upload input{
      display: none;
    }

    .upload label{
      background: DarkSlateBlue;
      color: white;
      padding: 2px 10px;
    }

    #keyConfContainer {
        height: 300px;
        width: 487px;
        border: 1px solid #000;
    }
    #keyconfTittle {
        text-transform: uppercase;
        height: 25px;
        width: 487px;
    }
    #keycap {
        float: left;
        height: 243px;
        width: 243px;
        border: 1px solid #000;
    }
    #options {
        height: 25px;
        width: 242px;
        float: right;
    }
    #menu {
        float: right;
        height: 250px;
        width: 242px;
    }
    #keycapconf {
        float: right;
        height: 275px;
        width: 242px;
    }
    </style>
</head>

<body>
    <div id="keyConfContainer">
        <div id="keyconfTittle">
            Modify a keycap
        </div>


        <div id="keycap">
            <div class="upload">
                <label for="my-input">Upload your image</label> <input accept=
                "image/*" id="my-input" name="" onchange="showMyImage(this)"
                type="file">
            </div>
            <br>


            <div id="bgcolor"><img alt="" id="thumbnil" src="" style=
            "width:100%; margin-top:10px;">
            </div>
        </div>


        <div id="keycapconf">
            <div id="options">
            </div>


            <div id="menu">
                Blackground-color: <input id="color" type="color"><br>
                Clip art library: 
                <!-- implementar la ventana con las imagenes--><br>
                Upload your image:

                <form action="demo_form.asp">
                    <input accept="image/*" name="pic" type="file" value=
                    "Upload a image"> <input type="submit" value="Change">
                </form>
            </div>
        </div>
    </div>
</body>
</html>

Here is a link for the jsfidlebut imageuploading doesnt work. http://jsfiddle.net/nmpj3qdp/

Any idea? is there any jquery that could fit my requierement?

Patrick Vibild
  • 331
  • 2
  • 14
  • have you checked this http://stackoverflow.com/questions/4459379/preview-an-image-before-it-is-uploaded? – gabereal Sep 23 '14 at 15:36

1 Answers1

0

Here's an updated fiddle.

You need to add

$('#imageFile').on('change', function(){ showMyImage(); });

and change the line in showMyImage to get the files to

 var files = $('#imageFile').prop("files");

I'm not sure what you mean by replacing the colour though. If you want to modify the loaded image there're plugins you can have a look at.

Update:

http://jsfiddle.net/nmpj3qdp/2/

This changes the background colour of the div that image is inside but you can't change the .png's back colour on client side unless you find a plugin for it.

artm
  • 8,321
  • 3
  • 21
  • 40
  • I would like to be able to add text and icon to the image that I upload this way. I allready have managed the colorbackground, you can uploead an image with transparences, and in the right chose a color and the background of the uploadedimage will change. EDIT: and by adding text and icons to the image, im not sayingthat the image needs to be changed and then uploaded like that. I just want to be able to show text and icons over that image. – Patrick Vibild Sep 23 '14 at 15:46
  • @PatrickVibild When you update an existing comment I don't get a notification, better add a new one. If you have a transparent icon image that you want to show on top of the loaded image, you can add it to your "#keycap" like the label you've added. – artm Sep 23 '14 at 15:58