# magick-wasm

> builds ImageMagick WASM for Magica, downloading sources and using docker.

Latest version **0.0.3** (published 2019-08-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install magick-wasm
pnpm add magick-wasm
yarn add magick-wasm
bun add magick-wasm
```

Provides the command `magick-wasm`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2019-08-06 |
| First published | 2019-08-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 365 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 106 |
| Author | Sebastian Gurin |
| Maintainers | cancerberosgx |
| Keywords | ImageMagick, emscripten, browser, node.js, API, CLI, Command Line, image processing, image format, image, library, typescript, Magica |

## Links

- npm: https://www.npmjs.com/package/magick-wasm
- Repository: https://github.com/cancerberoSgx/magica
- Homepage: https://www.npmjs.com/package/magica
- Issues: https://github.com/cancerberoSgx/magica
- npm.io page: https://npm.io/package/magick-wasm

## Dependencies (5)

- [ejs](https://npm.io/package/ejs.md) ^2.6.2
- [glob](https://npm.io/package/glob.md) ^7.1.4
- [shelljs](https://npm.io/package/shelljs.md) ^0.8.3
- [minimist](https://npm.io/package/minimist.md) ^1.2.0
- [misc-utils-of-mine-generic](https://npm.io/package/misc-utils-of-mine-generic.md) ^0.2.15

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 0.0.3 (latest) — 2019-08-06

## README

# magick-wasm

## Contents

<!-- toc -->

- [What?](#what)
- [Summary](#summary)
- [Usage](#usage)
- [Build result](#build-result)
- [Questions](#questions)
- [Hacking](#hacking)
  * [run-docker command (Internal)](#run-docker-command-internal)
  * [Replace magica's and run its tests (Internal)](#replace-magicas-and-run-its-tests-internal)
  * [Project versions registry](#project-versions-registry)
  * [(OLD) Notes about package versions and sources](#old-notes-about-package-versions-and-sources)
    + [ImageMagick](#imagemagick)
    + [png](#png)
    + [tiff](#tiff)
    + [zlib](#zlib)
    + [libjpeg](#libjpeg)
    + [freetype](#freetype)
    + [fftw](#fftw)
    + [webp](#webp)
    + [open-jpeg](#open-jpeg)
    + [turbo-jpeg (not included)](#turbo-jpeg-not-included)

<!-- tocstop -->

## What?

**WebAssembly build of ImageMagick and its libraries**

Produces JavaScript and WASM usable form Node.js and Browser with a simple API to call  ImageMagick command line utilities like `convert`, `identify`, `montage`, etc as an API.

Although it was implemented for [magica](https://github.com/cancerberoSgx/magica) it's totally independent of it and should be suitable for any use case needing.

See [main()](https://github.com/cancerberoSgx/magica/blob/master/src/main/main.ts) for simpler higher level implementation on top of it based on promises and defining a simple `File` interface.

## Summary

 * Generates shell scripts that: 
   * downloads latest versions of ImageMagick project and dependency libraries (mostly https://github.com/ImageMagick)
   * the script builder accepts settings for: 
     * enable/disable features like quantum-depth, hdri
     * build type: 'production', 'debug', 'incremental'
     * enable/disable dependency library
     * output folder, docker launch, script output, etc
   * WIP settings to re-use existing sources and optimize wasm build time and/or compile only certain libraries
   * WIP : command line tool to call the script generator
   * report git commits/sources for each project downloaded.

## Usage
 
TODO: the idea is to have a CLI that accepts parameters, builds scripts and optionally runs the build and tests. Right now what works instead is (`npx ts-node src/launch.ts`)

Install the tool globally (or locally and call it with `npx`)

```
npm install -g magick-wasm
```

Generates the default build type (production). in current directory and start it (docker needs to be up and running):
```
magick-wasm
```

Generates a "debug" build type, reusing current PREFIX/src folders in given `outputFolder`. 
It doesn't execute docker but prints instructions how to do it manually:

```
npx ts-node src/launch.ts --outputFolder $HOME/wasm/im --type debug --noClean --noRun
```


## Build result 

If everything is OK, (assuming default options), `emscripten_prefix/wasm/magick.wasm` and  `emscripten_prefix/wasm/magick.js` files should be generated.

In [magica](https://github.com/cancerberoSgx/magica) those can replace the ones at [src/imageMagick/compiled](https://github.com/cancerberoSgx/magica/src/imageMagick/compiled)

## Questions

(I need to ask)

 * whats the use Magick.Native is necessary ? should I include that? what's the gain? consider browser and node.js
 * Should I include font-config ? what's the gain?

## Hacking

 * `wasm-builds/emscripten-scripts/base.sh` base flags, debug or production build, etc
 * `wasm-builds/emscripten-scripts/build.sh` libraries build orchestrator
 * `src/defaults.ts` has defaults template context values (like depth, production/debug release, hdri, etc)
 * `src/types.ts` types of template context and CLI/API options

### run-docker command (Internal)

Docker needs to be installed and running.

```
cd build
sh emscripten-scripts/run-docker.sh
```

If everything is OK that should generate magick WASM files at `magick-wasm/build/emscripten_prefix/wasm/`. 

Also, since latest versions of git projects for ImageMagick and libraries are used, the versions of each are dump at `magick-wasm/build/versions.txt`.

### Replace magica's and run its tests (Internal)

The following command clone's magica project, replace the wasm files with the new ones, and runs its tests to verify nothing it's broken.

```
sh emscripten-scripts/test-wasm-magica.sh
```

Take into account that some tests could assume some magick capabilities or image format support that might not be so. Tests are not yet intelligent to detect current IM capabilities but they will be.

### Project versions registry

 * After a successfull build a file [versions.txt](build/versions.txt) file will be written with info about git repository urls and revisions used for each project


### (OLD) Notes about package versions and sources 

#### ImageMagick

latest from official repository:  https://github.com/ImageMagick/ImageMagick.git - cf00632d1

**No modifications needed** (we build all using --prefix and using PCK_CONFIG_PATH the configure script takes all dependencies from there.)

#### png

Latest from ImageMagick with little changes in mempng.c when free() C pointers (as Knicknic need to modify also to work with emscripten) https://github.com/cancerberosgx/png.git - 62b9724

TODO: discuss and PR to IM repo - I really don't understand (nto an expert) why this happen. Perhaps can be avoided using a emcc flag ? Also ask emscripten guys. 

Probably could solve other libraries similar problems.

#### tiff

Latest from ImageMagick tiff repository with no modifications. 
 
https://github.com/ImageMagick/tiff.git - 4965cb9

#### zlib 

zlib: latest ImageMagick zlib repository with no modifications
https://github.com/ImageMagick/zlib.git - 6a152c1

#### libjpeg

https://github.com/KnicKnic/libjpeg.git - fbaf3bf 

Using wasm-imagemagick (knicknic) version. had trouble reading files with mageMagick/jpeg-turbo and with the original libjpeg repos (see below). TODO: ask knicknic for changes since git diff is not clear. Also we could search for an alternative / updated or look which changes are needed in those.

#### freetype

freetype: https://github.com/ImageMagick/freetype.git - 598ad7c

emscripten freetype port also work but I prefer this version since is "official" for IM and updated.

#### fftw

(fast fourier transformations)

downloading http://www.fftw.org/fftw-3.3.8.tar.gz - no modifications needed - no version control found. Has a couple non exhaustive tests

#### webp

from official IM project without modifications: https://github.com/ImageMagick/webp.git. Although this library cmake has a js (WebAssembly target) using -DWEBP_BUILD_WEBP_JS=on it's not used and wasm is built as the rest of the libraries . Has read/write tests

#### open-jpeg 

Compiling fine from latest https://github.com/ImageMagick/open-jpeg.git. Has tests

#### turbo-jpeg (not included)

didn't work for most images since a problem in "markers" . There is some notes documenting this as limitation. But probably is an error related to why knicknic need to change the official library. In any case it compiles OK and writes OK but fails to read. 

TODO: ask knicknic for help to patch this version or update his, since the diff in git is not clear.

---
_Source: https://npm.io/package/magick-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
