Skip to content
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

Closed
wants to merge 18 commits into from

Conversation

dbolack-ab
Copy link
Collaborator

@dbolack-ab dbolack-ab commented Dec 31, 2023

This is a feature addition that adds the option of creating a thumbnail directly from the first page of the brew.

MagicImage

Remove 5ePHB assets and fonts.
There are two bugs that may be resolved by being on HTTPS
@dbolack-ab dbolack-ab marked this pull request as draft January 6, 2024 17:23
@calculuschild calculuschild temporarily deployed to homebrewery-pr-3219 January 17, 2024 17:22 Inactive
@calculuschild calculuschild temporarily deployed to homebrewery-pr-3219 January 18, 2024 20:04 Inactive
@dbolack-ab dbolack-ab self-assigned this Jan 21, 2024
@dbolack-ab dbolack-ab changed the title Magic thumbnail Automatic Brew thumbnail generation option Jan 25, 2024
@dbolack-ab dbolack-ab marked this pull request as ready for review January 25, 2024 19:51
@dbolack-ab
Copy link
Collaborator Author

Evaluators, please test with an assortment of complicated brews? I don't have a good library built up yet.

Copy link
Collaborator

@Gazook89 Gazook89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the generated image's "frame" is set by the brewRenderer.

For example, here is a good result:
image

Note that I have the brewRenderer sized to just fit the page.

But I open the preview panel up a bit with more space, this is the result:
image

This is true even with a default page, without custom styling. It seems likely that the capture is including the node's margin ? So with a wide brewRenderer, the margin is larger, and the captured image is very wide (and thus not fitting in the thumbnail box).

Edit: You can change the css of the captured node before the capture. I left a comment on that line.


There are a lot of cross-origin errors in the console when using this tool, all related to issues getting external stylesheets from fontawesome, googlefonts, etc.


ThumbnailCapture : async function() {
const bR = parent.document.getElementById('BrewRenderer');
const brewRenderer = bR.contentDocument || bR.contentWindow.document;
Copy link
Collaborator

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 between contentDocument and contentWindow.document? From what I can tell, it is the same thing?

Copy link
Collaborator Author

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.

@@ -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`} />
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

image
<i class="fas fa-camera"></i>

Maybe the fa-image icon is more indicative of "open from image library" rather than "generate new picture". Further, even though none of the other fields/controls currently have one, maybe this should have a tooltip?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent idea. I will do that.

Copy link
Collaborator

@Gazook89 Gazook89 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment about removing the page margin before capture.

(sorry for the "second" review, still getting the hang of them and didn't realize you couldn't append to an existing review)

const topPage = brewRenderer.getElementsByClassName('page')[0];
const props = this.props;

htmlimg.toPng(topPage, { preferredFontFormat: 'woff2' }).then(function(dataURL){
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the .page margin before doing the capture:

htmlimg.toPng(topPage, { preferredFontFormat: 'woff2', style: { margin: 'unset' } }).then(function(dataURL){

@Gazook89 Gazook89 added 🔍 R1 - Reviewed - Needs Discussion 💬 PR not okayed yet; needs reevaluation or closure 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging and removed 🔍 R1 - Reviewed - Needs Discussion 💬 PR not okayed yet; needs reevaluation or closure labels Feb 17, 2024
@dbolack-ab
Copy link
Collaborator Author

There are a lot of cross-origin errors in the console when using this tool, all related to issues getting external stylesheets from fontawesome, googlefonts, etc.

Yeah, that's been a problem for me here and I believe is at least one factor on the PDF generation. My thinking was that while imperfect it should handle the majority of coverpages.

@dbolack-ab
Copy link
Collaborator Author

I'm going to push this back to draft until I can sort out a way to deal with the Cross-site issues.

@dbolack-ab dbolack-ab marked this pull request as draft March 4, 2024 20:52
@calculuschild calculuschild added 🔍 R2 - Reviewed - Needs Help 🫱 PR is okayed but is stuck on an obstacle and removed 🔍 R3 - Reviewed - Awaiting Fixes 🔧 PR is okayed but needs fixes before merging labels Apr 4, 2024
@5e-Cleric
Copy link
Member

It seems like the generated image's "frame" is set by the brewRenderer.

For example, here is a good result:
image

Am i the only one to notice the Drop cap missing?

Also, we could use this with #3321 to auto generate previews?

@5e-Cleric
Copy link
Member

I'm assuming you have read https://developers.google.com/privacy-sandbox/3pcd

@5e-Cleric
Copy link
Member

Wow, tried the tool, so far:

bundle.js:92207 Error inlining remote css file DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92169:39
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92166:19
    at step (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92040:17)
    at Object.next (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91989:14)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91963:67
    at new Promise (<anonymous>)
    at __awaiter (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91945:10)
    at getCSSRules (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92160:10)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92246:32
xaZALQf_WN5H:1 Access to fetch at 'https://use.fontawesome.com/releases/v5.15.1/css/all.css' from origin 'https://homebrewery-pr-3219.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
bundle.js:92072 
 GET https://use.fontawesome.com/releases/v5.15.1/css/all.css net::ERR_FAILED
bundle.js:92204 Error loading remote stylesheet TypeError: Failed to fetch
    at bundle.js:92072:32
    at step (bundle.js:92040:17)
    at Object.next (bundle.js:91989:14)
    at bundle.js:91963:67
    at new Promise (<anonymous>)
    at __awaiter (bundle.js:91945:10)
    at fetchCSS (bundle.js:92063:10)
    at bundle.js:92197:30
    at Array.forEach (<anonymous>)
    at bundle.js:92166:19
bundle.js:92204 Error loading remote stylesheet DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92201:51
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92200:42
    at async Promise.all (index 1)
bundle.js:92220 Error while reading CSS rules from https://use.fontawesome.com/releases/v5.15.1/css/all.css DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92216:41
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92213:21
bundle.js:92220 Error while reading CSS rules from https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700 DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92216:41
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92213:21

@dbolack-ab
Copy link
Collaborator Author

Wow, tried the tool, so far:

bundle.js:92207 Error inlining remote css file DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92169:39
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92166:19
    at step (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92040:17)
    at Object.next (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91989:14)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91963:67
    at new Promise (<anonymous>)
    at __awaiter (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:91945:10)
    at getCSSRules (https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92160:10)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92246:32
xaZALQf_WN5H:1 Access to fetch at 'https://use.fontawesome.com/releases/v5.15.1/css/all.css' from origin 'https://homebrewery-pr-3219.herokuapp.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
bundle.js:92072 
 GET https://use.fontawesome.com/releases/v5.15.1/css/all.css net::ERR_FAILED
bundle.js:92204 Error loading remote stylesheet TypeError: Failed to fetch
    at bundle.js:92072:32
    at step (bundle.js:92040:17)
    at Object.next (bundle.js:91989:14)
    at bundle.js:91963:67
    at new Promise (<anonymous>)
    at __awaiter (bundle.js:91945:10)
    at fetchCSS (bundle.js:92063:10)
    at bundle.js:92197:30
    at Array.forEach (<anonymous>)
    at bundle.js:92166:19
bundle.js:92204 Error loading remote stylesheet DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92201:51
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92200:42
    at async Promise.all (index 1)
bundle.js:92220 Error while reading CSS rules from https://use.fontawesome.com/releases/v5.15.1/css/all.css DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92216:41
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92213:21
bundle.js:92220 Error while reading CSS rules from https://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700 DOMException: Failed to read the 'cssRules' property from 'CSSStyleSheet': Cannot access rules
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92216:41
    at Array.forEach (<anonymous>)
    at https://homebrewery-pr-3219.herokuapp.com/homebrew/bundle.js:92213:21

Hmm. Looks like the CORS related issues have gotten worse.

The only idea I've had around solving this is is to put proxy endpoint on the app and translate URLs when this function is called.

@calculuschild calculuschild temporarily deployed to homebrewery-pr-3219 May 12, 2024 16:36 Inactive
@dbolack-ab dbolack-ab added the blocked Waiting on a dependency, other feature, etc., first label May 20, 2024
@dbolack-ab
Copy link
Collaborator Author

Closing in favor of #3501.

@dbolack-ab dbolack-ab closed this May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked Waiting on a dependency, other feature, etc., first feature 🔍 R2 - Reviewed - Needs Help 🫱 PR is okayed but is stuck on an obstacle
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants