Skip to content

Commit

Permalink
Merge pull request #5388 from plotly/switch-to-probe-image-size
Browse files Browse the repository at this point in the history
Use probe-image-size module to read width and height of images
  • Loading branch information
archmoj committed Jan 8, 2021
2 parents d110973 + ff635ae commit c7e5a22
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 15 deletions.
75 changes: 65 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@
"glslify": "^7.1.1",
"has-hover": "^1.0.1",
"has-passive-events": "^1.0.0",
"image-size": "^0.7.5",
"is-mobile": "^2.2.2",
"mapbox-gl": "1.10.1",
"matrix-camera-controller": "^2.1.3",
Expand All @@ -109,6 +108,7 @@
"ndarray-linear-interpolate": "^1.0.0",
"parse-svg-path": "^0.1.2",
"polybooljs": "^1.2.0",
"probe-image-size": "^6.0.0",
"regl": "^1.6.1",
"regl-error2d": "^2.0.11",
"regl-line2d": "^3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/traces/image/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

'use strict';

var sizeOf = require('image-size');
var probeSync = require('probe-image-size/sync');
var dataUri = require('../../snapshot/helpers').IMAGE_URL_PREFIX;
var Buffer = require('buffer/').Buffer; // note: the trailing slash is important!

exports.getImageSize = function(src) {
var data = src.replace(dataUri, '');
var buff = new Buffer(data, 'base64');
return sizeOf(buff);
return probeSync(buff);
};
4 changes: 2 additions & 2 deletions test/image/export_test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var fs = require('fs');
var sizeOf = require('image-size');
var probeSync = require('probe-image-size/sync');

var getMockList = require('./assets/get_mock_list');
var getRequestOpts = require('./assets/get_image_request_options');
Expand Down Expand Up @@ -121,7 +121,7 @@ function testExport(mockName, format, cb) {
var didExport;

if(format === 'svg') {
var dims = sizeOf(imagePaths.test);
var dims = probeSync(fs.readFileSync(imagePaths.test));
didExport = (dims.width === WIDTH) && (dims.height === HEIGHT);
} else {
var stats = fs.statSync(imagePaths.test);
Expand Down

0 comments on commit c7e5a22

Please sign in to comment.