Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Use sharp to replace ImageMagick #366

Open
zhleonix opened this issue Jan 3, 2025 · 1 comment
Open

[Feature Request] Use sharp to replace ImageMagick #366

zhleonix opened this issue Jan 3, 2025 · 1 comment
Assignees

Comments

@zhleonix
Copy link

zhleonix commented Jan 3, 2025

Is your feature request related to a problem? Please describe.
ImageMagick installation is problematic on windows and even worse on managed windows desktop inside enterprise IT environment.
To use sharp, a native NodeJS module for image transformation, would help to reduce the dependency and make the setup easier.

Describe the solution you'd like
Rewrite ImageMagick task by using sharp API.

Describe alternatives you've considered
N/A

Additional context
N/A

@zhleonix
Copy link
Author

zhleonix commented Jan 3, 2025

Here is an example that I had tried to use sharp for SVG->PNG and can be run successfully with crossnote and vscode-markdown-preview-enhanced plugin:

import sharp from 'sharp';

export async function svgElementToPNGFile(
  svgElement: string,
  pngFilePath: string,
  imageMagickPath: string = '',
): Promise<string> {
  try {
    await sharp(
      Buffer.from(
        svgElement.replace(
          /font-family="[\w|\-|,|\s]+"/g,
          'font-family="Arial, sans-serif"',
        ),
      ),
    )
      .png()
      .toFile(pngFilePath);
  } catch (error) {
    throw new Error(
      'sharp conversion failure\n' +
        error.toString() +
        '\n\nPlease make sure you have libvips installed.',
    );
  }

  return pngFilePath;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants