All Projects → KnicKnic → Wasm Imagemagick

KnicKnic / Wasm Imagemagick

Licence: apache-2.0
Webassembly compilation of https://github.com/ImageMagick/ImageMagick & samples

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Wasm Imagemagick

Cometa
Super fast, on-demand and on-the-fly, image processing.
Stars: ✭ 8 (-98.19%)
Mutual labels:  image-processing, image, image-manipulation
Flyimg
Dockerized PHP7 application runs as a Microservice to resize and crop images on the fly. Get optimised images with MozJPEG, WebP or PNG using ImageMagick. Includes face detection, cropping, face blurring, image rotation and many other options. Abstract storage based on FlySystem in order to store images on any provider (local, AWS S3...).
Stars: ✭ 762 (+72.4%)
Mutual labels:  image-processing, image, imagemagick
Oblique
With Oblique explore new styles of displaying images
Stars: ✭ 633 (+43.21%)
Mutual labels:  image-processing, image, image-manipulation
Php Legofy
Transform your images as if they were made out of LEGO bricks.
Stars: ✭ 161 (-63.57%)
Mutual labels:  image-processing, image-manipulation, imagemagick
Bitmap
C++ Bitmap Library
Stars: ✭ 125 (-71.72%)
Mutual labels:  image-processing, image, image-manipulation
Smartcircle
✂️Automatically determine where to crop a circular image out of a rectangular.
Stars: ✭ 29 (-93.44%)
Mutual labels:  image-processing, image, webassembly
Magick
Magic, madness, heaven, sin
Stars: ✭ 362 (-18.1%)
Mutual labels:  image-processing, image-manipulation, imagemagick
Photon
⚡ Rust/WebAssembly image processing library
Stars: ✭ 963 (+117.87%)
Mutual labels:  image-processing, image-manipulation, webassembly
Nuxt Image Loader Module
An image loader module for nuxt.js that allows you to configure image style derivatives.
Stars: ✭ 135 (-69.46%)
Mutual labels:  image-processing, image-manipulation, imagemagick
Menyoki
Screen{shot,cast} and perform ImageOps on the command line 🌱 🏞️
Stars: ✭ 255 (-42.31%)
Mutual labels:  image-processing, image, image-manipulation
Lena.js
👩 Library for image processing
Stars: ✭ 432 (-2.26%)
Mutual labels:  image-processing, image-manipulation
Skeptick
Better ImageMagick for Ruby
Stars: ✭ 326 (-26.24%)
Mutual labels:  image-processing, imagemagick
Jekyll Gallery Generator
A Jekyll plugin that generates photo galleries from directories full of images.
Stars: ✭ 315 (-28.73%)
Mutual labels:  image-processing, imagemagick
Korkut
Quick and simple image processing at the command line. 🔨
Stars: ✭ 310 (-29.86%)
Mutual labels:  image-processing, image
Opence
Contrast Enhancement Techniques for low-light images
Stars: ✭ 333 (-24.66%)
Mutual labels:  image-processing, image-manipulation
Imgtoascii
A JavaScript implementation of a image to Ascii code
Stars: ✭ 331 (-25.11%)
Mutual labels:  image-processing, image-manipulation
Imageflow
High-performance image manipulation for web servers. Includes imageflow_server, imageflow_tool, and libimageflow
Stars: ✭ 3,643 (+724.21%)
Mutual labels:  image-manipulation, imagemagick
Ccextractor
CCExtractor - Official version maintained by the core team
Stars: ✭ 356 (-19.46%)
Mutual labels:  image-processing, image
Exifcleaner
Cross-platform desktop GUI app to clean image metadata
Stars: ✭ 305 (-31%)
Mutual labels:  image-processing, image
Imaginary
Fast, simple, scalable, Docker-ready HTTP microservice for high-level image processing
Stars: ✭ 4,107 (+829.19%)
Mutual labels:  image-processing, image

Web assembly ImageMagick Build Status

This project is not affiliated with ImageMagick , but is merely recompiling the code to be WebAssembly. I did this because I want to bring the power of ImageMagick to the browser.

Table of Contents

Demos and examples

Status

Image formats supported

Supports PNG, TIFF, JPEG, BMP, GIF, PhotoShop, GIMP, and more!

See a list of known supported formats in this demo

Features not supported

API

Reference API Documentation

Reference API Documentation

High level API and utilities

wasm-imagemagick comes with some easy to use APIs for creating image files from urls, executing multiple commands reusing output images and nicer command syntax, and utilities to handle files, html images, input elements, image comparison, metadata extraction, etc. Refer to API Reference Documentation for details.

import { buildInputFile, execute, loadImageElement } from 'wasm-imagemagick'

const { outputFiles, exitCode} = await execute({
  inputFiles: [await buildInputFile('http://some-cdn.com/foo/fn.png', 'image1.png')],
  commands: [
    'convert image1.png -rotate 70 image2.gif',
    // heads up: the next command uses 'image2.gif' which was the output of previous command:
    'convert image2.gif -scale 23% image3.jpg',
  ],
})
if(exitCode !== 0)
    await loadImageElement(outputFiles[0], document.getElementById('outputImage'))

Accessing stdout, stderr, exitCode

This other example executes identify command to extract information about an image. As you can see, we access stdout from the execution result and check for errors using exitCode and stderr:

import { buildInputFile, execute } from 'wasm-imagemagick'

const { stdout, stderr, exitCode } = await execute({
    inputFiles: [await buildInputFile('foo.gif')], 
    commands: `identify foo.gif`
})
if(exitCode === 0) 
    console.log('foo.gif identify output: ' + stdout.join('\n'))
else 
    console.error('foo.gif identify command failed: ' + stderr.join('\n'))

low-level example

As demonstration purposes, the following example doesn't use any helper provided by the library, only the low level call() function which only accept one command, in array syntax only:

import { call } from 'wasm-imagemagick'

// build an input file by fetching its content
const fetchedSourceImage = await fetch("assets/rotate.png")
const content = new Uint8Array(await fetchedSourceImage.arrayBuffer());
const image = { name: 'srcFile.png', content }

const command = ["convert", "srcFile.png", '-rotate', '90', '-resize', '200%', 'out.png']
const result = await call([image], command)

// is there any errors ?
if(result.exitCode !== 0)
    return alert('There was an error: ' + result.stderr.join('\n'))

// response can be multiple files (example split) here we know we just have one
const outputImage = result.processedFiles[0]

// render the output image into an existing <img> element
const outputImage = document.getElementById('outputImage')
outputImage.src = URL.createObjectURL(outputImage.blob)
outputImage.alt = outputImage.name

Importing the library in your project

With npm

npm install --save wasm-imagemagick

**IMPORTANT:

Don't forget to copy magick.wasm and magick.js files to the folder where your index.html is being served:

cp node_modules/wasm-imagemagick/dist/magick.wasm .
cp node_modules/wasm-imagemagick/dist/magick.js .

Then you are ready to import the library in your project like this:

import { execute} from 'wasm-imagemagick'

or like this if you are not using standard modules:

const execute = require('wasm-imagemagick').execute

Loading directly from html file

If you are not working in a npm development environment you can still load the library bundle .js file. It supports being imported as JavaScript standard module or as a UMD module.

Importing magickApi.js as a JavaScript standard module:

Basic version, just reference online https://knicknic.github.io/wasm-imagemagick/magickApi.js no files needed at all.

See samples/rotate#code.

Relevant portions called out below "..." means code is missing from example

  <script type='module'>
    //import the library to talk to imagemagick
    import * as Magick from 'https://knicknic.github.io/wasm-imagemagick/magickApi.js';

    // ...

    // Fetch the image to rotate, and call image magick
    let DoMagickCall = async function () {
      // ....

      // calling image magick with one source image, and command to rotate & resize image
      let processedFiles = await Magick.Call([{ 'name': 'srcFile.png', 'content': sourceBytes }], ["convert", "srcFile.png", "-rotate", "90", "-resize", "200%", "out.png"]);

      // ...
    };
    DoMagickCall();
  </script>

Working example source code.

Below examples need additional files coppied:

Copy magick.js, magick.wasm in the same folder as your html file.:

Importing a bundle as a JavaScript standard module:

<script type="module">
    import { execute, loadImageElement, buildInputFile } from '../../dist/bundles/wasm-imagemagick.esm-es2018.js'
    // ... same snippet as before
</script>

Working example source code

Using the UMD bundle in AMD projects (requirejs)

<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"></script>
<script src="../../dist/bundles/wasm-imagemagick.umd-es5.js"></script>
<script>
require(['wasm-imagemagick'], function (WasmImagemagick) {
    const { execute, loadImageElement, buildInputFile } = WasmImagemagick
    // ... same snippet as before

Working example source code

Using the UMD bundle without libraries

<script src="../../dist/bundles/wasm-imagemagick.umd-es5.js"></script>
<script>
    const { execute, loadImageElement, buildInputFile } = window['wasm-imagemagick']
    // ... same snippet as before

Working example source code

Build instructions

git clone --recurse-submodules https://github.com/KnicKnic/WASM-ImageMagick.git

cd WASM-ImageMagick

#ubuntu instructions
#   install node
sudo snap install --edge node --classic
#   install typescript
sudo npm install typescript -g
#   install docker
curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh
#   be sure to add your user to the to the docker group and relogin

# install and run build
npm install


#windows instructions
# currently broken
# If you really want a build, create a PR, 
# a build will get kicked off, click show all checks -> Details -> top right of the details page (in artifcats) 

# docker run --rm -it --workdir /code -v %CD%:/code wasm-imagemagick-build-tools bash ./build.sh

Produces magick.js, magickApi.js, & magick.wasm in the current folder.

Run tests

npm test will run all the tests.

npm run test-browser will run spec in a headless chrome browser. These tests are located at ./spec/.

npm run test-browser-server will serve the test so you can debug them with a browser.

npm run test-browser-start will run the server and start watching for file changes, recompile and restart the server for agile development.

npm test-node will run some tests with nodejs located at ./tests/rotate.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].