Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using JIC.js compress an image in python-flaks application #56

Open
vinayakinnoctive opened this issue Jan 3, 2018 · 0 comments
Open

Comments

@vinayakinnoctive
Copy link

vinayakinnoctive commented Jan 3, 2018

Hey , I am using JIC.js library for image compression and uploading it,
I need to accept this compressed image into python code.
Currently I am using request.files['imgInp'] to accept input.
How can i get compressed image?

This is my javascript code

     function readURL(input) {
        if (input.files && input.files[0]) {
        var output_format = "jpg";
        var file = input.files[0], 
        reader = new FileReader();
        reader.onload = function(event) {
        var i = document.getElementById("source_image");
            i.src = event.target.result;
            i.onload = function(){
                image_width=$(i).width(),
                image_height=$(i).height();

                if(image_width > image_height){
                    i.style.width="320px";
                }else{
                    i.style.height="300px";
                }
                i.style.display = "block";
                console.log("Image loaded");
            }             
        };     
        if(file.type=="image/png"){
            output_format = "png";
        }
        console.log("Filename:" + file.name);
        console.log("Filesize:" + (parseInt(file.size) / 1024) + " Kb");
        console.log("Type:" + file.type);         
        reader.readAsDataURL(file);

        ///////////////////////////////////////////////////////////////////////////////////////
        var result_image = document.getElementById('result_image');
        var source_image = document.getElementById('source_image');
        if (source_image.src == "") {
            alert("You must load an image first!");
            return false;
        }
        console.log("process start...");
        result_image.src = jic.compress(source_image,30,output_format).src;
        result_image.onload = function(){
            var image_width=$(result_image).width(),
            image_height=$(result_image).height();                 
            if(image_width > image_height){
                result_image.style.width="320px";
            }else{  
                result_image.style.height="300px";
            }
           result_image.style.display = "block";
        }
        console.log("process finished...");         
    }        

};

This is my html code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="/static/JIC.js"></script>

your image

your image

This is python code

@app.route('/updateuser',methods=['GET','POST'])
def updateuser():
file = request.files['imgInp']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant