remove imagemagick dependency and call using exec(), also optimize HLTB thumbnails after download

main
Wouter Groeneveld 10 months ago
parent bf5acb097c
commit db3cea5c0d

@ -113,7 +113,7 @@ With Pagefind, there's no need to integrate it into jam-my-stack, greatly simpli
Adds https://howlongtobeat.com/ game length (`MainGame`) and an ID to your front matter (keys `howlongtobeat_id` and `howlongtobeat_hrs`), provided you first added a property called `game_name`. (This gets substituted).
It also downloads a thumbnail of the cover image if you provided the dir as an option.
It also downloads a thumbnail of the cover image if you provided the dir as an option. The downloaded thumbnail is automatically optimized for the web using `mogrify` (this will emit a warning if you do not have ImageMagick installed locally).
So, Frontmatter like this:
@ -175,6 +175,8 @@ Same as `getWebmentions`.
Thanks to ideas from [rubenerd.com](https://rubenerd.com) and his [video.sh script](https://gitlab.com/rubenerd/rubenerd.com/-/blob/trunk/scripts/video.sh). This downloads a thumbnail using `youtube-dl`, smacks a play button on it using `convert`, and stores that in the specified folder. Use in conjunction with a Hugo shortcode to get rid of YouTube's iframes!
This method will fail if you do not have ImageMagick installed locally.
Usage example:
```js

@ -1,6 +1,6 @@
{
"name": "jam-my-stack",
"version": "1.0.30",
"version": "1.0.31",
"repository": {
"url": "https://github.com/wgroeneveld/jam-my-stack",
"type": "git"
@ -18,7 +18,6 @@
"fast-xml-parser": "^3.18.0",
"got": "11.8.3",
"howlongtobeat": "^1.5.1",
"imagemagick": "^0.1.3",
"parser-front-matter": "^1.6.4",
"youtube-dl-exec": "^1.2.4"
},

@ -8,6 +8,7 @@ const {promisify} = require('util');
const frontMatterParser = require('parser-front-matter');
const parse = promisify(frontMatterParser.parse.bind(frontMatterParser));
const exec = promisify(require('child_process').exec);
const stream = require('stream');
const pipeline = promisify(stream.pipeline);
@ -52,6 +53,10 @@ async function fillInHowLongToBeat(posts, downloadDir) {
if(downloadDir) {
await downloadThumbnail(game.imageUrl, game.id, downloadDir)
const { stdout, stderr } = await exec(`mogrify -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -format jpg -colorspace sRGB ${downloadDir}/${game.id}.jpg`)
if(stderr) {
console.log(`-- WARN: unable to mogrify downloaded JPG: ${stderr}`)
}
}
}
}

@ -3,7 +3,7 @@ const got = require("got");
const { createWriteStream, existsSync, unlinkSync } = require("fs");
const fs = require('fs').promises;
const { getFiles } = require('./../file-utils');
var im = require("imagemagick");
const { exec } = require('child_process');
async function downloadThumbnail(youtubeid, downloadDir, overlayImg) {
const dlLoc = `${downloadDir}/${youtubeid}.jpg`
@ -18,13 +18,10 @@ async function downloadThumbnail(youtubeid, downloadDir, overlayImg) {
const done = new Promise(function(resolve, reject) {
fStream.on('finish', () => {
var args = [
"-resize", "700x400", dlLoc,
"+repage", "+page", overlayImg, "-flatten", dlLoc
]
im.convert(args, function(err) {
if(err) reject(err)
resolve()
const child = exec(`convert -resize 700x400 -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -format jpg -colorspace sRGB ${dlLoc} +repage +page ${overlayImg} -flatten ${dlLoc}`)
child.on('exit', code => {
if(code != 0) reject(`Mogrify returned non-zero exit code: ${code}`)
resolve()
})
})

@ -2799,13 +2799,6 @@ fsevents@^2.1.2:
languageName: node
linkType: hard
"imagemagick@npm:^0.1.3":
version: 0.1.3
resolution: "imagemagick@npm:0.1.3"
checksum: 49a6479ae08a7b845ab13df835b87ecd46b8bf93a1872c7c0b3ace7858bf1edc7defd1f84dda9fe8e765051877a82487914551557939048236b7465a31d6f783
languageName: node
linkType: hard
"import-local@npm:^3.0.2":
version: 3.0.2
resolution: "import-local@npm:3.0.2"
@ -3214,7 +3207,6 @@ fsevents@^2.1.2:
fast-xml-parser: ^3.18.0
got: 11.8.3
howlongtobeat: ^1.5.1
imagemagick: ^0.1.3
jest: ^26.6.3
mockdate: ^3.0.2
parser-front-matter: ^1.6.4

Loading…
Cancel
Save