Croppie: Upload original image along with cropped version.

Created on 14 Sep 2017  路  3Comments  路  Source: Foliotek/Croppie

wrong question, please forgive me.

Most helpful comment

I think this option is very important and in my case I need it for my application so I found the solution for this which is very simple, just adding a few lines to your script.
in this case I created a global variable when binding the image so I can use it later when sending the data, this will make the magic.

$image_crop.croppie('bind', {
                url: e.target.result
            }).then(function(){
                $original_image = e.target.result;
            });         
        }

here is the full script
```
$(document).ready(function(){
$image_crop = $('#upload-image').croppie({

    viewport: {
        width: 200,
        height: 200,
        type: 'square'
    },
    boundary: {
        width: 300,
        height: 300
    }
});
$('#images').on('change', function () { 
    var reader = new FileReader();
    reader.onload = function (e) {
        $image_crop.croppie('bind', {
            url: e.target.result
        }).then(function(){
            $original_image = e.target.result;
        });         
    }
    reader.readAsDataURL(this.files[0]);
});
$('#cropped_image').on('click', function (ev) {
    $image_crop.croppie('result', {
        type: 'canvas',
        size: 'viewport'
    }).then(function (response) {
        $.ajax({
            url: "upload_test.php",
            type: "POST",
            data: {"image":response,"original_image":$original_image},
            success: function (data) {
            alert("yesss")
            }
        });
    });
});

});

then on the PHP file you process it the same way, basically just copy the code and change the name of the variables. 

$croped_image = $_POST['image'];
$original_image = $_POST['original_image'];
```

All 3 comments

I'm not sure if you're still needing help, but if you need the original and the cropped, that would be something you'd handle with your own code.

You're going to have better luck searching somewhere else for help on this one. Although it sounds like an interesting problem to solve, I don't have the time to help right now.

I think this option is very important and in my case I need it for my application so I found the solution for this which is very simple, just adding a few lines to your script.
in this case I created a global variable when binding the image so I can use it later when sending the data, this will make the magic.

$image_crop.croppie('bind', {
                url: e.target.result
            }).then(function(){
                $original_image = e.target.result;
            });         
        }

here is the full script
```
$(document).ready(function(){
$image_crop = $('#upload-image').croppie({

    viewport: {
        width: 200,
        height: 200,
        type: 'square'
    },
    boundary: {
        width: 300,
        height: 300
    }
});
$('#images').on('change', function () { 
    var reader = new FileReader();
    reader.onload = function (e) {
        $image_crop.croppie('bind', {
            url: e.target.result
        }).then(function(){
            $original_image = e.target.result;
        });         
    }
    reader.readAsDataURL(this.files[0]);
});
$('#cropped_image').on('click', function (ev) {
    $image_crop.croppie('result', {
        type: 'canvas',
        size: 'viewport'
    }).then(function (response) {
        $.ajax({
            url: "upload_test.php",
            type: "POST",
            data: {"image":response,"original_image":$original_image},
            success: function (data) {
            alert("yesss")
            }
        });
    });
});

});

then on the PHP file you process it the same way, basically just copy the code and change the name of the variables. 

$croped_image = $_POST['image'];
$original_image = $_POST['original_image'];
```

After 3 years, I really needed this. Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

guschnwg picture guschnwg  路  4Comments

nueverest picture nueverest  路  8Comments

bmalets picture bmalets  路  6Comments

powerbuoy picture powerbuoy  路  5Comments

wyzard picture wyzard  路  3Comments