Comments (8)
Please make a demo.
from konva.
Ok, i have reduced the code to the minimum viable reproduceable, here:
https://thebighouseproject.nz/mindmaps/thumbproblem.html (edit:link fixed)
Step 1: Load the page, then Click the save button, and note the image contains the expected bounds.
Step 2: Now drag the stage so that you can see the square labelled -500,-500. (or anywhere really). Click save, and notice the image does not contain the same image as found in step 1. There is large chunks missing.
Step3: click the rezero button. Click save, note the image is now again correct.
Where the stage is dragged to influences the bounds of the image regardless of what config object you send.
Cheers for looking at this man.
from konva.
So the work around for this is:
//upload a mindmap thumbnail
sendthumb: function() {
// There is a quirk in konva that corrupts images if the stage is not at 0,0
var originalPosition = {
x: mindmap.stage.x(),
y: mindmap.stage.y(),
};
mindmap.stage.position({x: 0, y: 0});
var bounds = mindmap.getbounds();
var dataURL = mindmap.stage.toDataURL({
x: bounds.x,
y: bounds.y,
width: bounds.width,
height: bounds.height
});
// Restore the original stage position
// this stage change seems to occur unnoticably to user
mindmap.stage.position(originalPosition);
//the rest of the image handling code
//goes here
//...
}
from konva.
Position of stage affects stage.toDataURL()
. So different output before/after drag is expected to me.
Passing x
and y
to stage.toDataURL()
work like an "offset" from its defined position.
Resetting position to {0, 0}
-> exporting -> restoring position back is very valid approach. You can use it if it makes things simpler.
from konva.
Do i get you right, that this would work?
var originalPosition = {
x: mindmap.stage.x(),
y: mindmap.stage.y(),
};
var dataURL = mindmap.stage.toDataURL({
x: -originalPosition.x,
y: -originalPosition.y,
});
from konva.
I am not sure about negativing it, but it should work.
from konva.
Ok here is another work around:
var dataURL = stage.toDataURL({
x: stage.x() + min.x,
y: stage.y() + min.y,
width: (max.x - min.x),
height: (max.y - min.y),
});
downloadURI(dataURL, 'stage.png');
I am curious what does the stage position have to do with image export? What use case does this behavior support?
from konva.
The default export should capture what is visible on the screen. So position must be applied.
from konva.
Related Issues (20)
- Cannot override shape.rotation() in on transform event
- Can you create a brush tool like this one https://github.com/acamposuribe/p5.brush?
- Container ignores canvas width HOT 1
- Transformer handle drag issue: losing control after dragging and clicking on stage HOT 15
- Rotating the object image using the rotate function HOT 2
- Documentation for old releases and migration guide HOT 1
- comment typo HOT 1
- Can't cornerRadius and shadow be shared on the react-Konva Image component? HOT 1
- `canvas` dependency missing for node HOT 2
- Smooth Scrolling of Bitmap Render on LED Display HOT 3
- Feature Request: Transformer support custom create anchor HOT 3
- determine length of a line given its points and tension HOT 2
- What is the correct way to fire a custom event using react-konva HOT 1
- Rotated circle size HOT 1
- Event when you mousedown and move outside canvas. HOT 1
- Can we draw an un-closed ellipse like below? HOT 1
- Text wrong line break if have Chinese and english word HOT 1
- Broken shadow after crop in safari HOT 3
- Problem with Loading Video (Konva.Node.create) HOT 1
- After caching the lines, if there is a scaling factor, the line width may appear abnormal
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 konva.