Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.

New feature : Crop result in Base64 #80

Closed
Lenacus opened this issue Oct 9, 2014 · 2 comments
Closed

New feature : Crop result in Base64 #80

Lenacus opened this issue Oct 9, 2014 · 2 comments

Comments

@Lenacus
Copy link

Lenacus commented Oct 9, 2014

Hi,

Just a simply and little code in JS to crop directly in Base64. With this, you can add the dataUrl (contains cropped picture) in hidden input and don't upload a big image but just the result.
Maybe you can add it in a new function in your (great) plugin.

Best regards.

Must have :
A canvas in html.

Nota :
$imgData is data from the function "done" in cropper.
150 is the wanted size in pixel.

Code JS:

    var canvas = document.getElementById('canvas'),
        context = canvas.getContext('2d'),
        image = new Image();

    canvas.width = canvas.height = 150;

    image.src = $image.prop('src');
    context.drawImage(image, $imgData.x, $imgData.y, $imgData.width, $imgData.height, 0, 0, canvas.width, canvas.height);
    dataUrl = canvas.toDataURL('image/jpeg');
@fengyuanchen
Copy link
Owner

Good idea!!!

fengyuanchen pushed a commit that referenced this issue Oct 21, 2014
- Supports zoom (#1, #79) and rotate(#81).
- Add 2 new options: "zoomable" and "rotatable".
- Add 6 new methods: "enable", "disable", "zoom", "rotate", "getDataURL"
(#80) and "setDragMode".
- Rename "release" method to "clear".
- Rename "setImgSrc" method to "replace".
- Rename "getImgInfo" method to "getImageData".
- Some other improvements.
@fengyuanchen
Copy link
Owner

This an awesome idea, and I have added it now. Thank you very much!!

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

No branches or pull requests

2 participants