javascript - 将图像文件拆分为两个单独的图像
问题描述
我的服务器上有一个高度为 50 000 像素的图像文件。我想保存 2 个 25 000px 的文件(原始图像的第一和第二部分)
关于如何做到这一点的任何建议?
谢谢
解决方案
清晰的图像包可能对这种情况有用。更具体地说是提取方法。
我添加了指向文档的链接,但这里有一个拆分图像的可能实现。
const sharp = require("sharp");
const originalFilename = "image.jpg";
const image = sharp(originalFilename);
// this is just a placeholder
const imageWidth = 500;
image
.extract({ left: 0, top: 0, width: imageWidth, height: 25000 })
.toFile("top.jpg", function(err) {
// Save the top of the image to a file named "top.jpg"
});
image
.extract({ left: 0, top: 25000, width: imageWidth, height: 25000 })
.toFile("bottom.jpg", function(err) {
// Save the bottom of the image to a file named "bottom.jpg"
});
我假设您可以重复使用原始清晰图像对象来调用提取函数两次。如果不是,您可能需要再次调用尖锐的构造函数。
推荐阅读
- wear-os - 如何在磨损操作系统的背景中获得加速度计传感器的响应?
- c# - Hyper-V 迭代网络适配器 C# Powershell Get-VM
- javascript - Papa.parse 复杂的承诺
- sql - 用于识别和替换电子邮件的 REGEXP
- python-3.x - Spyder 在导入部分显示警告
- jsf - PrimeFaces Datatable如何正确刷新inputText和selectBooleanCheckbox里面
- javascript - 未从 Firestore 获取数据
- javascript - 如何从 JupyterLab 扩展激活方法访问笔记本?
- javascript - 如何区分 JS 完成的滚动和用户完成的滚动?
- twitter-bootstrap - d3.js、sankey 和 bootstrap:更改所有颜色