const [image, setImage] = useState("");
const [imageWidth, setImageWidth] = useState(0);
const HandleImageInput = (e) => {
const reader = new FileReader();
let imageUrl;
reader.onload = () => {
if (reader.readyState === 2) {
imageUrl = reader.result;
setImage(imageUrl);
const imageEl = document.createElement("img");
imageEl.src = imageUrl;
imageEl.onload = () => {
const aspectRatio = imageEl.width / imageEl.height;
const newImageWidth = 120 * aspectRatio;
setImageWidth(newImageWidth);
};
document.getElementById("my_modal_2").showModal();
}
};
reader.readAsDataURL(e.target.files[0]);
};
function NewImage(props) {
const [url] = useImage(image);
return (
<Image {...props} image={url} draggable width={imageWidth} height={150} />
);
}
// Text Input
const [text, setText] = useState("");
const textInput = useRef();
const HandleSubmitText = (e) => {
e.preventDefault();
const text = textInput.current.value;
setText(text);
document.getElementById("my_modal_2").showModal();
};
function NewText(props) {
return (
<Text
{...props}
text={text}
draggable
fontSize={konvaControls.textFontSize}
/>
);
}
returning:
<NewImage
x={imageX}
y={imageY}
draggable
onDragEnd={(e) => {
setImageX(e.target.x()), setImageY(e.target.y());
}}
/>
<NewText
x={textX}
y={textY}
fill={textColor}
onDragEnd={(e) => {
setTextX(e.target.x()), setTextY(e.target.y());
}}
/>
</Layer>
In the above code I am unable to add multiple images onto the canvas, every time I add an image the texture is getting set with a new image, any fix?