Comments (2)
I made it!
Example:
<!DOCTYPE html>
<html>
<head>
<title>Jcrop Example</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="jcrop.css" />
</head>
<body>
<div style="padding:0 5%;">
<h1 style="font-family:Helvetica,sans-serif;">
Jcrop Example <span style="color:lightgray;">- draw some crops!</span>
</h1>
<img id="target" src="https://d3o1694hluedf9.cloudfront.net/market-750.jpg">
</div>
<canvas id="myCanvas" width="100" height="50" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script src="jcrop.js"></script>
<script>
setImage();
var jcp;
Jcrop.load('target').then(img => {
jcp = Jcrop.attach(img,{multi:false});
const rect = Jcrop.Rect.sizeOf(jcp.el);
jcp.newWidget(rect.scale(.7,.5).center(rect.w,rect.h));
jcp.focus();
jcp.setOptions({shadeOpacity:0.8});
});
// to fix security issue when trying to convert to Data URI
function setImage(){
document.getElementById('target').setAttribute('crossOrigin', 'anonymous');
document.getElementById('target').src = 'https://d3o1694hluedf9.cloudfront.net/market-750.jpg';
}
function getCoord(){
console.log(jcp.active.pos);
//document.querySelector("div.jcrop-widget.active").style.background = "red";
return jcp.active.pos;
}
setTimeout(function(){
document.querySelector("div.jcrop-widget.active").addEventListener("click", getCoord);
},1000);
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
function cropImage() {
let coords = getCoord();
console.log("coords",coords);
// reset canvas
c.setAttribute("width", coords.w) ;
c.setAttribute("height", coords.h);
ctx.clearRect(0, 0, coords.w, coords.h); // clear canvas
// add cropped image in canvas
var img = document.getElementById("target");
ctx.drawImage(img, coords.x,coords.y,coords.w,coords.h,0,0,coords.w,coords.h); //drawImage(sx,sy,swidth,sheight,x,y,width,height)
// convert canvas to DATA URI
var imgData = c.toDataURL("image/png").replace("image/png", "image/octet-stream");
console.log(imgData);
}
</script>
<button onclick="cropImage()">Crop it!</button>
</body>
</html>
from jcrop.
@Kamoba how to download image with multi-crop I set jcp = Jcrop.attach(img,{multi:false});
while console console.log(imgData);
on button click user can also download the image how can we do, Please help
from jcrop.
Related Issues (20)
- I want to learn how to do a cropping plugin myself
- How can I specify a minimum width and height for cropping? HOT 2
- On Create Event Handler
- Merge showcoords and updatepreview
- The problem with calling the setImage() method with file uploaded images out of whack with the instance width and height
- Is there an option to change the image selection area to be circular
- Firefox 86.0.1 - Problem with Cropping
- Quickstart docs for jQuery not available HOT 4
- 请提供react-jcrop版本呗
- Это дерьмо не работает. Не тратьте свое время HOT 1
- Options aren't documented
- Can you please help publish 2.0.X version to npm
- npm package is on 3.0.1
- jcrop.newCropper is not a function HOT 2
- trueSize or min, maxsize not working for large image
- Is this project maintained? HOT 1
- Broken example on jcrop.com due to wrong event name
- White image in the canva.
- Hello, if the picture is relatively large, how to get the coordinates of equal width?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jcrop.