import * as React from 'react'; import Page, { Grid, GridColumn } from '@atlaskit/page'; import { getOrientation, getFileInfo } from '../src'; import { InputWrapper, PreviewList, PreviewItem, Code, CloseButton, OrientationSelectWrapper, PreviewImageContainer, } from '../example-helpers/styled'; import Lozenge from '@uidu/lozenge'; const ORIENT_TRANSFORMS: { [key: number]: string } = { 1: 'none', 2: 'rotateY(180deg)', 3: 'rotate(180deg)', 4: 'rotate(180deg) rotateY(180deg)', 5: 'rotate(270deg) rotateY(180deg)', 6: 'rotate(90deg)', 7: 'rotate(90deg) rotateY(180deg)', 8: 'rotate(270deg)', }; interface ExamplePreview { filename: string; src: string; orientation: number; duration: number; } export interface ExampleState { previews: ExamplePreview[]; orientation: number; } class Example extends React.Component<{}, ExampleState> { state: ExampleState = { previews: [], orientation: 0, }; onChange = async (e: any) => { const { files } = e.target; const { previews } = this.state; for (let file of files) { const startTime = Date.now(); const fileInfo = await getFileInfo(file); const orientation = await getOrientation(file); const duration = Date.now() - startTime; previews.push({ filename: file.name, orientation, src: fileInfo.src, duration, }); } this.setState({ previews: [...previews] }); }; onSelectOrientation = (e: any) => { const orientation = parseInt(e.target.value, 10); this.setState({ orientation }); }; render() { const { orientation } = this.state; return (

Image Orientation Preview

@atlaskit/media-ui exports:{' '} async getOrientation(file:File): number

async Example:
const orientation: number = await getOrientation(file);

Select a local image to see it's Exif orientation (if available).
Currently only supports Exif / XMP tags in JPEG and{' '} PNG formats.

Use Orientation:  {this.renderPreviews()}
); } onRemovePreview = (index: number) => () => { const { previews } = this.state; previews.splice(index, 1); this.setState({ previews: [...previews] }); }; renderPreviews() { const { previews, orientation: forcedOrientation } = this.state; return previews.map((preview, i) => { // const orientation = // preview.orientation === null ? 1 : preview.orientation; const orientation = forcedOrientation === 0 ? preview.orientation : forcedOrientation; return (

filename:{' '} {preview.filename}

orientation:{' '} {orientation}

transform:{' '} {ORIENT_TRANSFORMS[orientation]}

duration: {preview.duration}ms

X
); }); } } export default () => ;