问题描述
我也曾在“情人/锐利问题”委员会上提出这个问题,但我希望那里有人可以对此提供任何提示。
我有一个lambda,它由SQS触发并引用了源图像。然后我以某种方式获取该图像,然后尝试sharpify
:D
摘录如下:
import axios from "axios";
import sharp from "sharp";
//first get the source image
try {
const source = (
await axios({
url: rawImage.sourceUrl,responseType: "arraybuffer"
})
).data;
sourceImageBuffer = Buffer.from(source);
console.log("sourceImageBuffer",sourceImageBuffer);
} catch (error) {
problemWithImage = "can't access source image";
console.log("getobject can't access source image",error);
}
//convert image to a sharp object
try {
if (!!sourceImageBuffer) {
imageBuffer = await sharp(sourceImageBuffer).toBuffer();
imageMetadata = await sharp(imageBuffer).Metadata();
}
} catch (error) {
console.log(
"can't process source image. is it an image? error ",error
);
problemWithImage = "can't process source image. is it an image?";
throw new Error(error);
}
每次都会引发以下错误:
2020-09-29T09:05:07.436Z 2d64036b-3a05-474f-a22a-93e3446204d6 INFO can't process source image. is it an image? error [Error: Input buffer contains unsupported image format]
我尝试使用s3.getobject或使用某种请求库来采购图像,但得到的结果相同。
如果我console.log sourceImageBuffer
,我会正确地得到一个<Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 02 02 02 03 02 02 02 03 03 03 03 04 06 04 04 04 04 04 08 06 06 05 ... 25119 more bytes>
。
当我在本地运行代码(在Mac而非docker上)时,它运行完美。
5天后,有500根白发,并阅读了Google可能为我提供的所有错误通知...我没主意了。
我应该尝试使用流而不是缓冲区吗?还是我在lambda中缺少图书馆?不知道。
示例图片:https://s3.eu-west-1.amazonaws.com/rp-p1-stage-core-images-cold-storage/724/724100/11121/1%3A1/kfmrixsc.jpeg
versions: {
cairo: '1.16.0',exif: '0.6.22',expat: '2.2.9',ffi: '3.3',fontconfig: '2.13.92',freetype: '2.10.2',fribidi: '1.0.10',gdkpixbuf: '2.40.0',gettext: '0.21',gif: '5.1.4',glib: '2.65.2',gsf: '1.14.47',harfbuzz: '2.7.1',jpeg: '2.0.5',lcms: '2.11',orc: '0.4.31',pango: '1.46.1',pixman: '0.40.0',png: '1.6.37',svg: '2.49.4',spng: '0.6.0',tiff: '4.1.0',vips: '8.10.0',webp: '1.1.0',xml: '2.9.10',zlib: '1.2.11'
}
format: {
jpeg: {
id: 'jpeg',input: { file: true,buffer: true,stream: true },output: { file: true,stream: true }
},png: {
id: 'png',webp: {
id: 'webp',tiff: {
id: 'tiff',magick: {
id: 'magick',input: { file: false,buffer: false,stream: false },output: { file: false,stream: false }
},openslide: {
id: 'openslide',dz: {
id: 'dz',ppm: {
id: 'ppm',fits: {
id: 'fits',gif: {
id: 'gif',svg: {
id: 'svg',heif: {
id: 'heif',pdf: {
id: 'pdf',vips: {
id: 'vips',raw: {
id: 'raw',stream: true }
}
}
package.json中的sharp版本“ sharp”:“ ^ 0.26.1”
解决方法
hm。所以就这样。 在该项目的另一部分中,我使用Sharp-Phesh为源图像生成唯一的哈希,因此我可以检查是否需要调整大小或旧源和新源是否匹配。
我怀疑Sharp-Phash中的严格依赖关系和我的项目存在冲突,整个事情都炸了。
我删除了尖锐的导入后,问题就消失了。