Skip to content

Commit

Permalink
Add photo print component
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Mar 22, 2019
1 parent 822167b commit 667d038
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/common/iiif.js
@@ -1,7 +1,7 @@
'use strict'

const { URL } = require('url')
const { rotate } = require('./math')
const { rotate, isHorizontal } = require('./math')


class Rotation {
Expand Down Expand Up @@ -44,6 +44,10 @@ class Rotation {
return `${this.mirror ? symbol : ''}${this.angle}`
}

get isHorizontal() {
return isHorizontal(this.angle)
}

get orientation() {
switch (this.angle) {
case 0:
Expand Down
9 changes: 5 additions & 4 deletions src/components/print/item.js
@@ -1,14 +1,15 @@
'use strict'

const React = require('react')
const { Photo } = require('./photo')
const { arrayOf, object } = require('prop-types')

const Item = ({ photos }) => (
<div className="item page">
<div className="item">
{photos.map(photo =>
<img
key={photo.id}
src={photo.path}/>)}
<Photo
{...photo}
key={photo.id}/>)}
</div>
)

Expand Down
41 changes: 41 additions & 0 deletions src/components/print/photo.js
@@ -0,0 +1,41 @@
'use strict'

const React = require('react')
const cx = require('classnames')
const { Rotation } = require('../../common/iiif')
const { bool, number, string } = require('prop-types')

const Photo = ({ angle, height, mirror, orientation, path, width }) => {
let rotation = Rotation
.fromExifOrientation(orientation)
.add({ angle, mirror })

return (
<div className={classes(width < height, rotation.isHorizontal)}>
<img
className={`iiif rot-${rotation.format('x')}`}
src={path}/>
</div>
)
}

Photo.propTypes = {
angle: number.isRequired,
height: number.isRequired,
mirror: bool.isRequired,
orientation: number.isRequired,
path: string.isRequired,
width: number.isRequired
}

const classes = (isPortrait, isHorizontal) => cx(
'photo',
'page',
isPortrait ?
(isHorizontal ? 'portrait' : 'landscape') :
(isHorizontal ? 'landscape' : 'portrait')
)

module.exports = {
Photo
}

0 comments on commit 667d038

Please sign in to comment.