Gathering detailed insights and metrics for blueimp-load-image-browserify
Gathering detailed insights and metrics for blueimp-load-image-browserify
Load images provided as File or Blob objects or via URL. Retrieve an optionally scaled, cropped or rotated HTML img or canvas element. Use methods to parse image metadata to extract IPTC and Exif tags as well as embedded thumbnail images, to overwrite the Exif Orientation value and to restore the complete image header after resizing.
npm install blueimp-load-image-browserify
Typescript
Module System
Node Version
NPM Version
JavaScript (93.75%)
HTML (3.82%)
CSS (2.24%)
Shell (0.19%)
Total Downloads
12,528
Last Day
15
Last Week
32
Last Month
76
Last Year
1,336
4,451 Stars
430 Commits
920 Forks
162 Watching
2 Branches
19 Contributors
Latest Version
1.11.1
Package Id
blueimp-load-image-browserify@1.11.1
Size
31.64 kB
NPM Version
2.1.10
Node Version
0.10.26
Cumulative downloads
Total Downloads
Last day
0%
15
Compared to previous day
Last week
113.3%
32
Compared to previous week
Last month
8.6%
76
Compared to previous month
Last year
3.2%
1,336
Compared to previous year
1
This is a fork of blueimp-load-image that supports CommonJS/browserify
and resolves the issue where it's broken if used in the server because of window
object.
Note that this is a temporary fix and still exposes loadImage
object globally.
##Browserify usage
var loadImage = require('blueimp-load-image-browserify/js/load-image');
loadImage(file, function(canvas) {
//See the main repo for more instructions
});
//If you need to use any of the extra files, e.g. the iOS fix, just include them after the main require:
var loadImage = require('blueimp-load-image-browserify/js/load-image');
require('blueimp-load-image-browserify/js/load-image-ios');
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.
Include the (minified) JavaScript Load Image script in your HTML markup:
1<script src="js/load-image.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-ios.js"></script> 3<script src="js/load-image-orientation.js"></script> 4<script src="js/load-image-meta.js"></script> 5<script src="js/load-image-exif.js"></script> 6<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. "http://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 = "http://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:
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 parseMetaData callback data contains 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:
Scaling megapixel images in iOS (iPhone, iPad, iPod) can result in distorted (squashed) images.
The Load Image iOS scaling fixes extension resolves these issues.
The JavaScript Load Image script is released under the MIT license.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
12 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-01-27
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