From c5b030f9b00fad5b3ee5e34c6d095519084bb2cf Mon Sep 17 00:00:00 2001 From: Sam Wilkins <35748010+samwilkins333@users.noreply.github.com> Date: Wed, 12 Feb 2020 17:05:26 -0500 Subject: added native width and height to imported images --- src/client/documents/Documents.ts | 10 +++++++--- src/scraping/buxton/final/BuxtonImporter.ts | 30 +++++++++++++++++++---------- 2 files changed, 27 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts index 24dd9ae91..86f68e883 100644 --- a/src/client/documents/Documents.ts +++ b/src/client/documents/Documents.ts @@ -367,11 +367,15 @@ export namespace Docs { const { __images } = device; delete device.__images; const { ImageDocument, StackingDocument } = Docs.Create; - const constructed = __images.map(relative => Utils.prepend(relative)); - const deviceImages = constructed.map((url, i) => ImageDocument(url, { title: `image${i}.${extname(url)}` })); + const constructed = __images.map(({ url, nativeWidth, nativeHeight }) => ({ url: Utils.prepend(url), nativeWidth, nativeHeight })); + const deviceImages = constructed.map(({ url, nativeWidth, nativeHeight }, i) => ImageDocument(url, { + title: `image${i}.${extname(url)}`, + _nativeWidth: nativeWidth, + _nativeHeight: nativeHeight + })); const doc = StackingDocument(deviceImages, { title: device.title, _LODdisable: true }); const deviceProto = Doc.GetProto(doc); - deviceProto.hero = new ImageField(constructed[0]); + deviceProto.hero = new ImageField(constructed[0].url); Docs.Get.DocumentHierarchyFromJson(device, undefined, deviceProto); Doc.AddDocToList(parentProto, "data", doc); } else if (errors) { diff --git a/src/scraping/buxton/final/BuxtonImporter.ts b/src/scraping/buxton/final/BuxtonImporter.ts index f9726872c..098671942 100644 --- a/src/scraping/buxton/final/BuxtonImporter.ts +++ b/src/scraping/buxton/final/BuxtonImporter.ts @@ -11,7 +11,7 @@ import { strictEqual } from "assert"; interface DocumentContents { body: string; - imageUrls: string[]; + imageData: ImageData[]; hyperlinks: string[]; captions: string[]; embeddedFileNames: string[]; @@ -29,7 +29,7 @@ export interface DeviceDocument { primaryKey: string; secondaryKey: string; attribute: string; - __images: string[]; + __images: ImageData[]; hyperlinks: string[]; captions: string[]; embeddedFileNames: string[]; @@ -57,6 +57,12 @@ interface Processor { required?: boolean; } +interface ImageData { + url: string; + nativeWidth: number; + nativeHeight: number; +} + namespace Utilities { export function numberValue(raw: string) { @@ -265,12 +271,12 @@ async function extractFileContents(pathToDocument: string): Promise { +async function writeImages(zip: any): Promise { const allEntries = Object.values(zip.entries()).map(({ name }) => name); const imageEntries = allEntries.filter(name => imageEntry.test(name)); - const imageUrls: string[] = []; + const imageUrls: ImageData[] = []; for (const mediaPath of imageEntries) { const streamImage = () => new Promise((resolve, reject) => { zip.stream(mediaPath, (error: any, stream: any) => error ? reject(error) : resolve(stream)); @@ -308,19 +314,23 @@ async function writeImages(zip: any): Promise { await DashUploadUtils.outputResizedImages(streamImage, imageDir, generatedFileName, ext); - imageUrls.push(`/files/images/buxton/${generatedFileName}`); + imageUrls.push({ + url: `/files/images/buxton/${generatedFileName}`, + nativeWidth: width, + nativeHeight: height + }); } return imageUrls; } function analyze(fileName: string, contents: DocumentContents): AnalysisResult { - const { body, imageUrls, captions, hyperlinks, embeddedFileNames } = contents; + const { body, imageData, captions, hyperlinks, embeddedFileNames } = contents; const device: any = { hyperlinks, captions, embeddedFileNames, - __images: imageUrls + __images: imageData }; const errors: { [key: string]: string } = { fileName }; -- cgit v1.2.3-70-g09d2