0.0.15 • Published 10 years ago

ajpeg v0.0.15

Weekly downloads
4
License
MIT
Repository
github
Last release
10 years ago

AJPEG (Alpha-JPEG)

PNG File size can be a hassle. This library provides transparency support to JPEG images allowing you to get lightweight images and speed up your page load.

AJPEG GULP encoder allows you to split PNG file into 2 separate files :

  • a JPEG file without transparency that you can compress
  • a PNG file containing the alpha channel only

The decoder loads the 2 files and fast restore the alpha channel using native html canvas composite operation.

Demo

https://mbossan.github.io/AJPEG/

Install

$ npm install --save-dev ajpeg
Graphics Magick

Make sure GraphicsMagick is installed on your system and properly set up in your PATH.

brew install graphicsmagick
  • Ubuntu:
apt-get install graphicsmagick

Encoding

const gulp = require('gulp'),
    ajpeg = require('ajpeg');

gulp.task('default', function () {
    return gulp.src("src/*.png")
        .pipe(ajpeg(60))
        .pipe(gulp.dest('dist/'));
});

API

ajpeg(quality)

Type: number Default: 60

JPEG compression from 1 to 100

Decoding

Setup

Include the library

<script src="decoder/dist/ajpeg.min.js" type="application/javascript"></script>

OR

const AJPEG = require('decoder/dist/ajpeg.min');

Usage

Load into a Canvas

new AJPEG().load("assets/rp1_00000.jpg", function () {
    document.body.appendChild(this.toCanvas());
});

Load into an Image

new AJPEG().load("assets/rp1_00000.jpg", function () {
    var newImg = document.createElement('img');
    newImg.src = this.toDataURL();
    document.body.appendChild(newImg);
});

Autoload via html attribute parsing

<img alpha-src="assets/rp1_00000.jpg"/>
<script>
AJPEG.parse();
</script>

License

MIT ©

0.0.15

10 years ago

0.0.14

10 years ago

2.0.0

10 years ago

0.0.13

10 years ago

0.0.12

10 years ago

0.0.11

10 years ago

0.0.10

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago