Skip to content

Quadratica/JavaScript-Load-Image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JavaScript Load Image

A JavaScript library to load and transform image files.

Table of contents

Demo

JavaScript Load Image Demo

Description

JavaScript Load Image is a library to load images provided as File or Blob objects or via URL.
It returns an optionally scaled and/or cropped HTML img or canvas element via an asynchronous callback.
It also provides a method to parse image meta data to extract Exif tags and thumbnails and to restore the complete image header after resizing.

Setup

Include the (minified) JavaScript Load Image script in your HTML markup:

<script src="js/load-image.min.js"></script>

Or alternatively, choose which components you want to include:

<script src="js/load-image.js"></script>
<script src="js/load-image-ios.js"></script>
<script src="js/load-image-orientation.js"></script>
<script src="js/load-image-meta.js"></script>
<script src="js/load-image-exif.js"></script>
<script src="js/load-image-exif-map.js"></script>

Usage

Image loading

In your application code, use the loadImage() function like this:

document.getElementById('file-input').onchange = function (e) {
    loadImage(
        e.target.files[0],
        function (img) {
            document.body.appendChild(img);
        },
        {maxWidth: 600} // Options
    );
};

Image scaling

It is also possible to use the image scaling functionality with an existing image:

var scaledImage = loadImage.scale(
    img, // img or canvas element
    {maxWidth: 600}
);

Requirements