Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vincerubinetti committed Jun 7, 2024
1 parent c68acc0 commit 9f850fc
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 37 deletions.
38 changes: 18 additions & 20 deletions .github/check.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
const { readdirSync, readFileSync, existsSync } = require("fs");
const { exec } = require("./util");
import { readdirSync, readFileSync, existsSync } from "fs";
import { ExifTool } from "exiftool-vendored";

// install exiftool
exec("sudo apt install exiftool");
const exiftool = new ExifTool({ taskTimeoutMillis: 5000 });

checkDimensions("./images", 600, 600);
checkDimensions("./print", 1200, 1200);
await checkDimensions("./images", 600, 600);
await checkDimensions("./print", 1200, 1200);

checkList("software.json");
checkList("groups.json");

exiftool.end();

// check list of entries in json file
function checkList(filename) {
console.info(`Checking list "${filename}"`);
Expand Down Expand Up @@ -40,29 +41,27 @@ function checkList(filename) {
}
}

// check dimensions of images in directory
function checkDimensions(
directory,
// check dimensions of images in folder
async function checkDimensions(
folder,
expectedWidth,
expectedHeight,
extension = "png"
) {
// get all images matching extension in directory
const paths = readdirSync(directory)
// get all images matching extension in folder
const paths = readdirSync(folder)
.filter((filename) => filename.endsWith(`.${extension}`))
.map((filename) => `${directory}/${filename}`);
.map((filename) => `${folder}/${filename}`);

for (const [index, path] of Object.entries(paths)) {
console.info(`Checking "${path}" (${+index + 1} of ${paths.length})`);

// extract dimensions
const [width, height] = exec(
`exiftool -s3 -ImageWidth -ImageHeight ${path}`,
false
)
.split(/\s/)
.filter(Boolean)
.map(Number);
const {
ImageWidth: width,
ImageHeight: height,
ColorType: colorspace,
} = await exiftool.read(path);

// check dimensions
if (width !== expectedWidth || height !== expectedHeight)
Expand All @@ -71,7 +70,6 @@ function checkDimensions(
);

// check color space
const colorspace = exec(`exiftool -s3 -ColorType ${path}`, false);
if (!colorspace.toLowerCase().includes("rgb"))
throw Error(`Colorspace "${colorspace}", expected RGB`);
}
Expand Down
23 changes: 17 additions & 6 deletions .github/clean.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
const { exec } = require("./util");
import { readdirSync, unlinkSync } from "fs";
import { ExifTool } from "exiftool-vendored";

// install exiftool
exec("sudo apt install exiftool");
const exiftool = new ExifTool({ taskTimeoutMillis: 5000 });

// strip all metadata to ensure consistency
exec("exiftool -All= -r -overwrite_original ./images");
exec("exiftool -All= -r -overwrite_original ./print");
await stripMeta("./images");
await stripMeta("./print");

exiftool.end();

// strip all metadata from all images in folder to ensure consistency
async function stripMeta(folder) {
await exiftool.deleteAllTags(folder, ["-recurse", "-overwrite_original"]);
// delete originals
readdirSync(folder)
.filter((filename) => filename.endsWith("_original"))
.map((filename) => `${folder}/${filename}`)
.forEach(unlinkSync);
}
7 changes: 0 additions & 7 deletions .github/util.js

This file was deleted.

12 changes: 11 additions & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,15 @@ jobs:
with:
ref: ${{ github.head_ref }}

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install packages
run: |
bun add exiftool-vendored@26
bun install
- name: Run script
run: node ./.github/check.js
run: bun ./.github/check.js
12 changes: 11 additions & 1 deletion .github/workflows/clean.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,18 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest

- name: Install packages
run: |
bun add exiftool-vendored@26
bun install
- name: Run script
run: node ./.github/clean.js
run: bun ./.github/clean.js

- name: Commit changed files
uses: stefanzweifel/git-auto-commit-action@v5
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ The order of entries on the website is shuffled randomly on each page visit to n

1. [Fork this repo](https://github.dev/CU-DBMI/wall-of-software) and make one or more changes.
1. Open a pull request (PR).
Check "Allow edits by maintainers".
Name the PR the canonical name(s) of the software/group(s) you're changing, using commas for multiple, e.g. "Word Lapse, Preprint Similarity Search".
1. Shortly after opening the PR, a link will appear that shows a preview of the website with your changes (if any).
Add `?print` at the end of the url to view the print versions of images instead.
Expand Down Expand Up @@ -59,7 +58,7 @@ To remove/change entries, edit the above files as needed.

## Images

Images should meet the following standards:
Images must meet the following standards:

- Unique, visually appealing logo or other graphical representation of your software/group.
- Not up-scaled, stretched, or otherwise blurry/noisy/distorted/etc.
Expand Down

0 comments on commit 9f850fc

Please sign in to comment.