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

Error reading arraybuffer in production environment #1270

Closed
ArSrNa opened this issue Jan 7, 2024 · 1 comment
Closed

Error reading arraybuffer in production environment #1270

ArSrNa opened this issue Jan 7, 2024 · 1 comment

Comments

@ArSrNa
Copy link

ArSrNa commented Jan 7, 2024

Expected Behavior

Correctly read the arraybuffer in the development environment after webpack packaging, and correctly process the trimmed output arraybuffer

Current Behavior

Crop the center of the picture with jimp

async function splitImage(buffer) {
  // Load the image from buffer
  const image = await Jimp.read(buffer);
  // Get image dimensions
  const { width, height } = image.bitmap;
  // Calculate half width and half height
  const halfWidth = Math.floor(width / 2);
  const halfHeight = Math.floor(height / 2);
  // Crop and encode each quadrant as base64
  const lti = image.clone().crop(0, 0, halfWidth, halfHeight).getBufferAsync(Jimp.MIME_JPEG);
  const rti = image.clone().crop(halfWidth, 0, halfWidth, halfHeight).getBufferAsync(Jimp.MIME_JPEG);
  const lbi = image.clone().crop(0, halfHeight, halfWidth, halfHeight).getBufferAsync(Jimp.MIME_JPEG);
  const rbi = image.clone().crop(halfWidth, halfHeight, halfWidth, halfHeight).getBufferAsync(Jimp.MIME_JPEG);
  // Wait for all quadrant images to be encoded as base64
  // const [lt, rt, lb, rb] = await Promise.all([lti, rti, lbi, rbi]);
  console.log('Image split into quadrants and encoded as base64 successfully.');
  return await Promise.all([lti, rti, lbi, rbi]);
}

Everything is normal in the development environment, but once packaged, an error will occur
It uses the framework of electron-reactboiler-plate, including the configuration of electron, webpack, etc. Packaged as an asar and encrypted the asar file with asarmor

//afterPack.js
const asarmor = require('asarmor');
const { join } = require("path");

exports.default = async ({ appOutDir, packager }) => {
  try {
    const asarPath = join(packager.getResourcesDir(appOutDir), 'app.asar');
    console.log(`asarmor applying patches to ${asarPath}`);
    const archive = await asarmor.open(asarPath);
    archive.patch(); // apply default patches
    await archive.write(asarPath);
  } catch (err) {
    console.error(err);
  }
};

This also happens when sharp is used again. issue: lovell/sharp#3924

Failure Information (for bugs)

(node:22532) UnhandledPromiseRejectionWarning: TypeError: en.read is not a function
    at dn (A:\ai-storyboard\resources\app.asar\dist\main\main.js:2:1290045)
    at IpcMainImpl.<anonymous> (A:\ai-storyboard\resources\app.asar\dist\main\main.js:2:1294662)
    at IpcMainImpl.emit (node:events:513:28)
    at WebContents.<anonymous> (node:electron/js2c/browser_init:2:88759)
    at WebContents.emit (node:events:513:28)
(node:22532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)

Steps to Reproduce

image

Context

  • Jimp Version: 0.22.10
  • Operating System: Windows 11
  • Node version: 20.10.0

Failure Logs

@ArSrNa
Copy link
Author

ArSrNa commented Jan 7, 2024

Using require instead of import statement, the issue was solved

@ArSrNa ArSrNa closed this as completed Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant