-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automatic Brew thumbnail generation option #3219
Changes from 8 commits
27d53f2
699f64c
1192307
180a8c8
c6c0a46
33021e1
14a37c1
cea05a3
83ae4f9
81148b4
f0a8020
9848e4b
5d87508
ec5f825
b86502a
9d6076f
5494c02
e458b9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ const request = require('../../utils/request-middleware.js'); | |
const Nav = require('naturalcrit/nav/nav.jsx'); | ||
const Combobox = require('client/components/combobox.jsx'); | ||
const StringArrayEditor = require('../stringArrayEditor/stringArrayEditor.jsx'); | ||
|
||
const htmlimg = require('html-to-image'); | ||
const Themes = require('themes/themes.json'); | ||
const validations = require('./validations.js'); | ||
|
||
|
@@ -31,6 +31,8 @@ const MetadataEditor = createClass({ | |
title : '', | ||
description : '', | ||
thumbnail : '', | ||
thumbnailSm : null, | ||
thumbnailLg : null, | ||
tags : [], | ||
published : false, | ||
authors : [], | ||
|
@@ -56,9 +58,24 @@ const MetadataEditor = createClass({ | |
}); | ||
}, | ||
|
||
|
||
ThumbnailCapture : async function() { | ||
const bR = parent.document.getElementById('BrewRenderer'); | ||
const brewRenderer = bR.contentDocument || bR.contentWindow.document; | ||
const topPage = brewRenderer.getElementsByClassName('page')[0]; | ||
const props = this.props; | ||
|
||
htmlimg.toPng(topPage, { preferredFontFormat: 'woff2' }).then(function(dataURL){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove the htmlimg.toPng(topPage, { preferredFontFormat: 'woff2', style: { margin: 'unset' } }).then(function(dataURL){ |
||
props.metadata.thumbnail = 'Page 1'; | ||
props.metadata.thumbnailSm = dataURL; | ||
props.onChange(props.metadata); | ||
}); | ||
}, | ||
|
||
renderThumbnail : function(){ | ||
if(!this.state.showThumbnail) return; | ||
return <img className='thumbnail-preview' src={this.props.metadata.thumbnail || homebreweryThumbnail}></img>; | ||
const imgURL = this.props.metadata.thumbnail.startsWith('Page 1') ? this.props.metadata.thumbnailSm : this.props.metadata.thumbnail; | ||
return <img className='thumbnail-preview' src={imgURL || homebreweryThumbnail}></img>; | ||
}, | ||
|
||
handleFieldChange : function(name, e){ | ||
|
@@ -333,6 +350,9 @@ const MetadataEditor = createClass({ | |
<button className='display' onClick={this.toggleThumbnailDisplay}> | ||
<i className={`fas fa-caret-${this.state.showThumbnail ? 'right' : 'left'}`} /> | ||
</button> | ||
<button className='display' onClick={this.ThumbnailCapture}> | ||
<i className={`fas fa-image`} /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think that switching to a camera icon is something to consider? ![]()
Maybe the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an excellent idea. I will do that. |
||
</button> | ||
</div> | ||
</div> | ||
{this.renderThumbnail()} | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious why this is an
OR
betweencontentDocument
andcontentWindow.document
? From what I can tell, it is the same thing?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My memory of the reference code is that it should be the same but for some browser situations, it may not be.