1234567891011121314151617181920212223242526272829303132333435 |
- import gm from 'gm';
- import path from 'node:path';
- import { getImagicPath, getTempPath } from './utils';
- // macos install gm imagemagick https://github.com/aheckmann/gm/blob/master/README.md
- const gmInst =
- process.platform === 'win32'
- ? gm.subClass({
- imageMagick: '7+',
- appPath: getImagicPath(),
- })
- : gm.subClass({ imageMagick: '7+' });
- function cropImage(imgPath: string): Promise<string> {
- return new Promise((resolve, reject) => {
- const outpath = path.join(getTempPath(), '001.png');
- gmInst(imgPath)
- .crop(500, 200, 0, 0)
- .write(outpath, (err) => {
- if (!err) {
- return resolve(outpath);
- }
- return reject(err);
- });
- });
- }
- const commonApi = {
- cropImage,
- };
- export type CommonApi = typeof commonApi;
- export default commonApi;
|