diff options
author | Bob Zeleznik <zzzman@gmail.com> | 2019-05-24 14:10:32 -0400 |
---|---|---|
committer | Bob Zeleznik <zzzman@gmail.com> | 2019-05-24 14:10:32 -0400 |
commit | 01d172a91d9a140129d2dd938c3289d7a0d25f16 (patch) | |
tree | 976091e440abd7f77364cdb45eca582595ef6d0a /src/client/documents/Documents.ts | |
parent | 3fce8beb887962d97c9fb880bb7a8e836ddf7bf4 (diff) |
cleaned up nativewidth/height for Image and Video and some PDF stuff.
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r-- | src/client/documents/Documents.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index ae190a989..1f4b76384 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -34,6 +34,7 @@ import { StrokeData, InkField } from "../../new_fields/InkField"; import { dropActionType } from "../util/DragManager"; import { DateField } from "../../new_fields/DateField"; import { UndoManager } from "../util/UndoManager"; +var requestImageSize = require('request-image-size'); export interface DocumentOptions { x?: number; @@ -216,7 +217,16 @@ export namespace Docs { } export function ImageDocument(url: string, options: DocumentOptions = {}) { - return CreateInstance(imageProto, new ImageField(new URL(url)), options); + let inst = CreateInstance(imageProto, new ImageField(new URL(url)), options); + requestImageSize(url) + .then((size: any) => { + if (!inst.proto!.nativeWidth) { + inst.proto!.nativeWidth = size.width; + } + inst.proto!.nativeHeight = Number(inst.proto!.nativeWidth!) * size.height / size.width; + }) + .catch((err: any) => console.log(err)); + return inst; // let doc = SetInstanceOptions(GetImagePrototype(), { ...options, layoutKeys: [KeyStore.Data, KeyStore.Annotations, KeyStore.Caption] }, // [new URL(url), ImageField]); // doc.SetText(KeyStore.Caption, "my caption..."); |