Gathering detailed insights and metrics for poshaughnessy-blueimp-load-image
Gathering detailed insights and metrics for poshaughnessy-blueimp-load-image
Gathering detailed insights and metrics for poshaughnessy-blueimp-load-image
Gathering detailed insights and metrics for poshaughnessy-blueimp-load-image
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. 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.
npm install poshaughnessy-blueimp-load-image
Typescript
Module System
Node Version
NPM Version
JavaScript (91.96%)
HTML (6.38%)
CSS (1.66%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
142 Commits
2 Watchers
3 Branches
1 Contributors
Updated on Oct 27, 2016
Latest Version
2.8.1
Package Id
poshaughnessy-blueimp-load-image@2.8.1
Size
263.41 kB
NPM Version
2.15.8
Node Version
4.4.7
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
4
A JavaScript library to load and transform image files.
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.
Include the (combined and minified) JavaScript Load Image script in your HTML markup:
1<script src="js/load-image.all.min.js"></script>
Or alternatively, choose which components you want to include:
1<script src="js/load-image.js"></script> 2<script src="js/load-image-orientation.js"></script> 3<script src="js/load-image-meta.js"></script> 4<script src="js/load-image-exif.js"></script> 5<script src="js/load-image-exif-map.js"></script>
In your application code, use the loadImage() function like this:
1document.getElementById('file-input').onchange = function (e) {
2 loadImage(
3 e.target.files[0],
4 function (img) {
5 document.body.appendChild(img);
6 },
7 {maxWidth: 600} // Options
8 );
9};
It is also possible to use the image scaling functionality with an existing image:
1var scaledImage = loadImage.scale( 2 img, // img or canvas element 3 {maxWidth: 600} 4);
The JavaScript Load Image library has zero dependencies.
However, JavaScript Load Image is a very suitable complement to the Canvas to Blob library.
The loadImage() function accepts a
File or
Blob object or a simple image URL
(e.g. 'https://example.org/image.png'
) as first argument.
If a File or
Blob is passed as parameter, it
returns a HTML img element if the browser supports the
URL API or a
FileReader object if
supported, or false.
It always returns a HTML
img element when
passing an image URL:
1document.getElementById('file-input').onchange = function (e) {
2 var loadingImage = loadImage(
3 e.target.files[0],
4 function (img) {
5 document.body.appendChild(img);
6 },
7 {maxWidth: 600}
8 );
9 if (!loadingImage) {
10 // Alternative code ...
11 }
12};
The img element or FileReader object returned by the loadImage() function allows to abort the loading process by setting the onload and onerror event handlers to null:
1document.getElementById('file-input').onchange = function (e) { 2 var loadingImage = loadImage( 3 e.target.files[0], 4 function (img) { 5 document.body.appendChild(img); 6 }, 7 {maxWidth: 600} 8 ); 9 loadingImage.onload = loadingImage.onerror = null; 10};
The second argument must be a callback function, which is called when the image has been loaded or an error occurred while loading the image. The callback function is passed one argument, which is either a HTML img element, a canvas element, or an Event object of type error:
1var imageUrl = "https://example.org/image.png"; 2loadImage( 3 imageUrl, 4 function (img) { 5 if(img.type === "error") { 6 console.log("Error loading image " + imageUrl); 7 } else { 8 document.body.appendChild(img); 9 } 10 }, 11 {maxWidth: 600} 12);
The optional third argument to loadImage() is a map of options:
canvas: true
.canvas: true
.0
and requires canvas: true
.0
and requires canvas: true
.0
and requires canvas: true
.0
and requires canvas: true
.true
.true
.16/9
).aspectRatio
also enables the crop
option.window.devicePixelRatio
unless the scaled image is not
rendered on screen.1
and requires canvas: true
.0.5
, each step
scales the image to half the size, before reaching the target dimensions.canvas: true
.true
.crop
option also enables the canvas
option.integer
in the range of 1
to 8
or the boolean
value true
.true
, it will set the orientation value based on the EXIF data of
the image, which will be parsed automatically if the exif library is available.orientation
also enables the canvas
option.orientation
to true
alsoe enables the meta
option.true
.true
.true
.They can be used the following way:
1loadImage( 2 fileOrBlobOrUrl, 3 function (img) { 4 document.body.appendChild(img); 5 }, 6 { 7 maxWidth: 600, 8 maxHeight: 300, 9 minWidth: 100, 10 minHeight: 50, 11 canvas: true 12 } 13);
All settings are optional. By default, the image is returned as HTML img element without any image size restrictions.
If the Load Image Meta extension is included, it is also possible to parse image
meta data.
The extension provides the method loadImage.parseMetaData, which can be used
the following way:
1loadImage.parseMetaData(
2 fileOrBlob,
3 function (data) {
4 if (!data.imageHead) {
5 return;
6 }
7 // Combine data.imageHead with the image body of a resized file
8 // to create scaled images with the original image meta data, e.g.:
9 var blob = new Blob([
10 data.imageHead,
11 // Resized images always have a head size of 20 bytes,
12 // including the JPEG marker and a minimal JFIF header:
13 loadImage.blobSlice.call(resizedImage, 20)
14 ], {type: resizedImage.type});
15 },
16 {
17 maxMetaDataSize: 262144,
18 disableImageHead: false
19 }
20);
The third argument is an options object which defines the maximum number of bytes to parse for the image meta data, allows to disable the imageHead creation and is also passed along to segment parsers registered via loadImage extensions, e.g. the Exif parser.
Note:
Blob objects of resized images can be created via
canvas.toBlob().
If you include the Load Image Exif Parser extension, the argument passed to the
callback for parseMetaData will contain the additional property exif if
Exif data could be found in the given image.
The exif object stores the parsed Exif tags:
1var orientation = data.exif[0x0112];
It also provides an exif.get() method to retrieve the tag value via the tag's mapped name:
1var orientation = data.exif.get('Orientation');
By default, the only available mapped names are Orientation and
Thumbnail.
If you also include the Load Image Exif Map library, additional tag mappings
become available, as well as two additional methods, exif.getText() and
exif.getAll():
1var flashText = data.exif.getText('Flash'); // e.g.: 'Flash fired, auto mode', 2 3// A map of all parsed tags with their mapped names as keys and their text values: 4var allTags = data.exif.getAll();
The Exif parser also adds additional options for the parseMetaData method, to disable certain aspects of the parser:
The JavaScript Load Image script is released under the MIT license.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More