Skip to content

Commit

Permalink
use probe-image-size instead of image-size
Browse files Browse the repository at this point in the history
  • Loading branch information
bmstefanski committed Mar 3, 2022
1 parent ab07f2a commit 6b1b2a0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 17 deletions.
4 changes: 2 additions & 2 deletions packages/plaiceholder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
},
"dependencies": {
"blurhash": "1.1.4",
"image-size": "1.0.0",
"node-cache": "5.1.2",
"node-fetch": "2.6.7"
"node-fetch": "2.6.7",
"probe-image-size": "^7.2.3"
}
}
26 changes: 13 additions & 13 deletions packages/plaiceholder/src/get-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import fs from "fs";
import path from "path";
import NodeCache from "node-cache";
import fetch from "node-fetch";
import sizeOf from "image-size";
import probe from "probe-image-size";
import sharp from "sharp";
import { arrayChunk } from "./utils";

Expand All @@ -19,17 +19,17 @@ interface IGetImageSizeReturn {
}

interface IGetImageSize {
(file: TGetImageSizeParam): IGetImageSizeReturn;
(file: TGetImageSizeParam): Promise<IGetImageSizeReturn>;
}

const getImageSize: IGetImageSize = (file) => {
const { width, height, type } = sizeOf(file);

return {
width,
height,
type,
};
const getImageSize: IGetImageSize = async (file) => {
if (Buffer.isBuffer(file)) {
let { width, height, type } = await probe(require('fs').createReadStream(file));
return { width, height, type };
} else {
let { width, height, type } = await probe(file, { rejectUnauthorized: false });
return { width, height, type };
}
};

/* loadImage
Expand Down Expand Up @@ -73,7 +73,7 @@ interface ILoadImage {

const loadImage: ILoadImage = async (imagePath) => {
if (Buffer.isBuffer(imagePath)) {
const imageSize = getImageSize(imagePath);
const imageSize = await getImageSize(imagePath);

return {
file: imagePath,
Expand All @@ -86,7 +86,7 @@ const loadImage: ILoadImage = async (imagePath) => {

if (imagePath.startsWith("http")) {
const buffer = await loadRemoteImage(imagePath);
const imageSize = getImageSize(buffer);
const imageSize = await getImageSize(buffer);

return {
file: buffer,
Expand All @@ -103,7 +103,7 @@ const loadImage: ILoadImage = async (imagePath) => {
);

const file = path.join("./public/", imagePath);
const imageSize = getImageSize(file);
const imageSize = await getImageSize(file);

return {
file,
Expand Down
30 changes: 28 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6528,7 +6528,7 @@ dateformat@^3.0.0:
resolved "https://registry.yarnpkg.com/dateformat/-/dateformat-3.0.3.tgz#a6e37499a4d9a9cf85ef5872044d62901c9889ae"
integrity sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q==

[email protected], debug@^2.2.0, debug@^2.3.3, debug@^2.6.0:
debug@2, debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0:
version "2.6.9"
resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f"
integrity sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==
Expand Down Expand Up @@ -8830,7 +8830,7 @@ [email protected]:
slash "^3.0.0"
which-pm-runs "^1.0.0"

[email protected], iconv-lite@^0.4.24:
[email protected], iconv-lite@^0.4.24, iconv-lite@^0.4.4:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==
Expand Down Expand Up @@ -10776,6 +10776,7 @@ minipass-fetch@^1.3.0, minipass-fetch@^1.3.2:
resolved "https://registry.yarnpkg.com/minipass-fetch/-/minipass-fetch-1.3.3.tgz#34c7cea038c817a8658461bf35174551dce17a0a"
integrity sha512-akCrLDWfbdAWkMLBxJEeWTdNsjML+dt5YgOI4gJ53vuO0vrmYQkUPxa6j6V65s9CcePIr2SSWqjT2EcrNseryQ==
dependencies:
encoding "^0.1.12"
minipass "^3.1.0"
minipass-sized "^1.0.3"
minizlib "^2.0.0"
Expand Down Expand Up @@ -11007,6 +11008,15 @@ napi-build-utils@^1.0.1:
resolved "https://registry.yarnpkg.com/napi-build-utils/-/napi-build-utils-1.0.2.tgz#b1fddc0b2c46e380a0b7a76f984dd47c41a13806"
integrity sha512-ONmRUqK7zj7DWX0D9ADe03wbwOBZxNAfF20PlGfCWQcD3+/MakShIHrMqx9YwPTfxDdF1zLeL+RGZiR9kGMLdg==

needle@^2.5.2:
version "2.9.1"
resolved "https://registry.yarnpkg.com/needle/-/needle-2.9.1.tgz#22d1dffbe3490c2b83e301f7709b6736cd8f2684"
integrity sha512-6R9fqJ5Zcmf+uYaFgdIHmLwNldn5HbK8L5ybn7Uz+ylX/rnOsSp1AHcvQSrCaFN+qNM1wpymHqD7mVasEOlHGQ==
dependencies:
debug "^3.2.6"
iconv-lite "^0.4.4"
sax "^1.2.4"

[email protected]:
version "0.6.2"
resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.2.tgz#feacf7ccf525a77ae9634436a64883ffeca346fb"
Expand Down Expand Up @@ -12814,6 +12824,15 @@ prismjs@^1.23.0:
resolved "https://registry.yarnpkg.com/prismjs/-/prismjs-1.25.0.tgz#6f822df1bdad965734b310b315a23315cf999756"
integrity sha512-WCjJHl1KEWbnkQom1+SzftbtXMKQoezOCYs5rECqMN+jP+apI7ftoflyqigqzopSO3hMhTEb0mFClA8lkolgEg==

probe-image-size@^7.2.3:
version "7.2.3"
resolved "https://registry.yarnpkg.com/probe-image-size/-/probe-image-size-7.2.3.tgz#d49c64be540ec8edea538f6f585f65a9b3ab4309"
integrity sha512-HubhG4Rb2UH8YtV4ba0Vp5bQ7L78RTONYu/ujmCu5nBI8wGv24s4E9xSKBi0N1MowRpxk76pFCpJtW0KPzOK0w==
dependencies:
lodash.merge "^4.6.2"
needle "^2.5.2"
stream-parser "~0.3.1"

process-nextick-args@~2.0.0:
version "2.0.1"
resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"
Expand Down Expand Up @@ -14893,6 +14912,13 @@ std-env@^2.2.1:
dependencies:
ci-info "^3.0.0"

stream-parser@~0.3.1:
version "0.3.1"
resolved "https://registry.yarnpkg.com/stream-parser/-/stream-parser-0.3.1.tgz#1618548694420021a1182ff0af1911c129761773"
integrity sha1-FhhUhpRCACGhGC/wrxkRwSl2F3M=
dependencies:
debug "2"

stream-throttle@^0.1.3:
version "0.1.3"
resolved "https://registry.yarnpkg.com/stream-throttle/-/stream-throttle-0.1.3.tgz#add57c8d7cc73a81630d31cd55d3961cfafba9c3"
Expand Down

0 comments on commit 6b1b2a0

Please sign in to comment.