UNPKG

pgm-utils

Version:

A PGM Utils

118 lines (92 loc) 2.91 kB
# PGMUtils #### Introduction A toolkit for parsing and generating PGM files #### Version History | Version Number | Update Content | Updater | | -------------- | -------------------------- | ----------- | | 1.0.0 | PGM parsing and generation toolkit | CorrineCao | #### Installation Tutorial 1. npm install pgm-utils 2. yarn add pgm-utils #### Usage Instructions 1. Parse PGM to ImageData ``` <Upload customRequest={async (info: any) => { const { file: originFileObj } = info; if (originFileObj.name.endsWith('.pgm')) { const pgmImg: ImageData = await PGMUtils.PGMTool.getImageDataByPGMBlob(originFileObj); } }} > <Button type="primary">Upload and parse PGM file</Button> </Upload> ``` 2. Generate PGM from ImageData ``` const pgmBlob: Uint8Array = PGMUtils.PGMTool.getPGMByImageData(imageData); ``` 3. Unzip and parse zip files with pgm, yaml, and json files ``` <Upload customRequest={async (info: any) => { const { file: originFileObj } = info; if (info.file.name.endsWith('.zip')) { if (originFileObj) { PGMUtils.DeflateTool.inflatePKG(originFileObj).then((res) => { console.log('>>>>res:', res); }); } } }} > <Button type="primary">Upload and parse compressed PGM file</Button> </Upload> ``` 4. Compress files and return a file object. It supports direct export of ZIP format files, which can include JSON, PGM, and YAML file formats. File names can be customized. ``` import PGMUtils from 'pgm-utils'; const record: Record<string, any> = {}; record['test.json'] = { name: 'test', ... }; record['test.pgm'] = ImageData; record['test.yaml'] = { name: 'test', origin: [0,0,0], ... } PGMUtils.DeflateTool.deflatePKG(record, 'compressed name'); ``` 5. Directly compress and obtain a File object of ZIP type ``` const file = await PGMUtils.DeflateTool.getDeflatePKG(record, 'compressed name'); ``` 6. Compress and directly export the ZIP file ``` PGMUtils.DeflateTool.exportDeflatePKG(record, 'compressed name'); ``` 7. Get the content of the uploaded YAML file ``` <Upload customRequest={async (info: any) => { const { file: originFileObj } = info; if (originFileObj.name.endsWith('.yaml')) { const yamlInfo = await PGMUtils.YamlTool.getYamlInfoByBlob(originFileObj); } }} > <Button type="primary">Upload YAML file</Button> </Upload> ``` 8. Convert string data into YAML file object data ``` const yamlInfo = PGMUtils.YamlTool.getYamlInfoByContent(yamlContent); ``` 9. Convert YAML object data into string-type data ``` const yamlContent = PGMUtils.YamlTool.getContentByYamlInfo(yamlInfo); ``` #### Contribute CorrineCao