Make images smaller using best-in-class codecs, right in the browser.
JavaScript
Hqx fix (#629)
Jake Archibaldb6fae0eb4c7e
diff --git a/codecs/hqx/Dockerfile b/codecs/hqx/Dockerfileindex 1142b581..d0287f33 100644--- a/codecs/hqx/Dockerfile+++ b/codecs/hqx/Dockerfile@@ -1,7 +1,8 @@FROM ubuntuRUN apt-get update && \apt-get install -qqy git build-essential cmake python2.7-RUN git clone --recursive https://github.com/WebAssembly/wabt /usr/src/wabt++RUN git clone --depth 1 --recursive https://github.com/WebAssembly/wabt /usr/src/wabtRUN mkdir -p /usr/src/wabt/buildWORKDIR /usr/src/wabt/buildRUN cmake .. -DCMAKE_INSTALL_PREFIX=/opt/wabt && \@@ -14,5 +15,7 @@ RUN rustup install nightly && \cargo install wasm-packCOPY --from=0 /opt/wabt /opt/wabt-ENV PATH="/opt/wabt/bin:${PATH}"+RUN mkdir /opt/binaryen && \+ curl -L https://github.com/WebAssembly/binaryen/releases/download/1.38.32/binaryen-1.38.32-x86-linux.tar.gz | tar -xzf - -C /opt/binaryen --strip 1+ENV PATH="/opt/binaryen:/opt/wabt/bin:${PATH}"WORKDIR /srcdiff --git a/codecs/hqx/build.sh b/codecs/hqx/build.shindex 413db29d..04f11c9f 100755--- a/codecs/hqx/build.sh+++ b/codecs/hqx/build.sh@@ -9,6 +9,9 @@ echo "============================================="rustup run nightly \wasm-pack build --target no-moduleswasm-strip pkg/squooshhqx_bg.wasm+ echo "Optimising WASM so it doesn't break Chrome (this takes like 10-15mins. get a cup of tea)"+ echo "Once https://bugs.chromium.org/p/chromium/issues/detail?id=97480 is fixed, we can remove this step"+ wasm-opt -Os --no-validation -o pkg/squooshhqx_bg.wasm pkg/squooshhqx_bg.wasmrm pkg/.gitignore)echo "============================================="diff --git a/codecs/hqx/pkg/squooshhqx_bg.wasm b/codecs/hqx/pkg/squooshhqx_bg.wasmindex b180905b..bf18ec0f 100644Binary files a/codecs/hqx/pkg/squooshhqx_bg.wasm and b/codecs/hqx/pkg/squooshhqx_bg.wasm differdiff --git a/src/codecs/resize/options.tsx b/src/codecs/resize/options.tsxindex 325c30a2..624b46a0 100644--- a/src/codecs/resize/options.tsx+++ b/src/codecs/resize/options.tsx@@ -24,19 +24,6 @@ interface State {const sizePresets = [0.25, 0.3333, 0.5, 1, 2, 3, 4];-/**- * Should we allow the user to select hqx? Chrome currently has a wasm bug, so we currently avoid it- * there, unless overridden.- * crbug.com/974804- */-const allowHqx: boolean = (() => {- const url = new URL(location.href);- return url.searchParams.has('allow-hqx')- // Yep. UA sniffing. Let's hope we can remove this soon.- // Block browsers with Chrome/, unless they also have Edge/ (since the Edge UA includes Chrome/)- || !navigator.userAgent.includes('Chrome/') || navigator.userAgent.includes('Edge/');-})();-export default class ResizerOptions extends Component<Props, State> {state: State = {maintainAspect: true,@@ -163,7 +150,7 @@ export default class ResizerOptions extends Component<Props, State> {<option value="mitchell">Mitchell</option><option value="catrom">Catmull-Rom</option><option value="triangle">Triangle (bilinear)</option>- {allowHqx && <option value="hqx">hqx (pixel art)</option>}+ <option value="hqx">hqx (pixel art)</option><option value="browser-pixelated">Browser pixelated</option><option value="browser-low">Browser low quality</option><option value="browser-medium">Browser medium quality</option>