Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High image reso #49

Open
wants to merge 2 commits into
base: nifty-ink-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 74 additions & 1 deletion packages/react-app/src/CreateInk.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
DownloadOutlined,
UploadOutlined,
InfoCircleOutlined,
BookOutlined
BookOutlined,
FileImageOutlined
} from "@ant-design/icons";
import {
Row,
Expand Down Expand Up @@ -210,6 +211,8 @@ export default function CreateInk(props) {
//const [loadedLines, setLoadedLines] = useState()

const [drawingSaved, setDrawingSaved] = useState(true);
const [isPreviewInk, setIsPreviewInk ] = useState(false);
const [previewImageData, setPreviewImageData ] = useState("");

const portraitRatio = 1.7;
const portraitCalc =
Expand Down Expand Up @@ -435,6 +438,41 @@ export default function CreateInk(props) {
return result;
};

const handlePreviewVisible = v => {
setIsPreviewInk(v);
};
const PreviewInk = async () => {
await setSending(true);
let imageData = await drawingCanvas.current.canvas.drawing.toDataURL("image/png");
// await setPreviewImageData(imageData);
// setSending(false);

// test code
// const _el = new Image();
// _el.src = imageData;
// _el.style.width = (size[0]) + "px";
// _el.style.height = (size[1]) + "px";
// await document.body.appendChild(_el);

const _i = new Image();
_i.src = await imageData;
_i.style.width = (size[0]*2) + "px";
_i.style.height = (size[1]*2) + "px";
_i.onload = async () => {
const _c = document.createElement('canvas');
const _ct = _c.getContext('2d');
_c.width = (size[0] * 2) ;
_c.height = (size[1] * 2) ;
await _ct.drawImage(_i, 0, 0, size[0] * 2, size[1] * 2);
// await document.body.appendChild(_c);

let _d = await _c.toDataURL();
await setPreviewImageData(_d);
setSending(false);
}

}

const createInk = async values => {
console.log("Inking:", values);

Expand Down Expand Up @@ -814,6 +852,41 @@ export default function CreateInk(props) {
>
<PlaySquareOutlined /> PLAY
</Button>
<Popover
content={
<div>
<img
width={size[0]}
height={size[1]}
src={previewImageData}
/>
</div>
}
overlayStyle={{paddingRight: '30px'}}
fitToScreen={true}
placement="bottom"
title="Preview Ink"
trigger="click"
visible={isPreviewInk}
onVisibleChange={handlePreviewVisible}
>
<Button
disabled={
canvasDisabled ||
(drawingCanvas.current && !drawingCanvas.current.lines.length)
}
onClick={() => {
if (
canvasDisabled ||
(drawingCanvas.current && !drawingCanvas.current.lines)
)
return;
PreviewInk();
}}
>
<FileImageOutlined /> Preview Ink
</Button>
</Popover>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion packages/react-app/src/NftyWallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Button, Badge, Tabs, Row, Col, Drawer, Layout, Menu } from "antd";
import { MenuOutlined } from "@ant-design/icons";
import { PlusOutlined } from "@ant-design/icons";
import { useContractReader, useLocalStorage } from "./hooks";
import { RelayProvider } from "@opengsn/gsn";
import { RelayProvider } from "@opengsn/provider";
import { Account, Faucet } from "./components";
import { createClient } from "@supabase/supabase-js";
import Holdings from "./Holdings.js";
Expand Down