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: Input file is missing on Ubuntu 20.04 #3192

Closed
saadanjum opened this issue Apr 17, 2022 · 3 comments
Closed

ERROR: Input file is missing on Ubuntu 20.04 #3192

saadanjum opened this issue Apr 17, 2022 · 3 comments
Labels

Comments

@saadanjum
Copy link

Hi,

I developed a code snippet using sharp for adding a frame to a provided image. It works extremely well on my development machine (MacBook Air M1, 8gb Memory). But when run the same code on my development server (Azure VM, Ubuntu, 20.04). I get the error Input file is missing. Here is what I have tried so far,

I double checked the paths and even tried to provide absolute paths to files.

I read somewhere that this can happen if low on memory, So I upgraded my VM and gave it 4gb ram. Tried the code when approx 3.5gb was available. still same error.

One thing I noticed is that the error occurs when I call toBuffer or toFile on the last step of the complete chain.

I am creating SVGs to write text on the image. (Is that supported on displayless Ubuntu)?

Following is my code.

const sharp = require('sharp')
const { dirname } = require('path');
const appDir = dirname(require.main.filename);

let foodText = 'Awesome Double Patty Beef Burger';
let locationText = 'KFC, Bahria Town, Civic Center, Phase 4';
const foodIconPath = `${appDir}/icons/spoon-and-fork.png`;
const locationIconPath = `${appDir}/icons/location-red.png`;
const logoPath = `${appDir}/icons/group39.png`
const centerImagePath = `${appDir}/icons/Best-Burger-4.jpeg`

const outputFilename = 'newImage323.png'

const textMaxLength = 40

const swotifyImage = (centerImagePath, foodText, locationText, outputFilename, foodIconPath, locationIconPath, logoPath) => {
  if (locationText.length > textMaxLength) {
    locationText = locationText.substr(0, textMaxLength);
    locationText += '...';
  }
  
  if (foodText.length > textMaxLength) {
    foodText = foodText.substr(0, textMaxLength);
    foodText += '...';
  }

  const foodTextSVG = `
    <svg width="900" height="60">
    <text fill="#ef3b36" font-size="30" font-family="Tahoma"  x="0" y="50">${foodText}</text>
    </svg>
    `;

  const foodTextSVGBuffer = Buffer.from(foodTextSVG);

  const locationTextSVG = `
    <svg width="600" height="60">
    <text fill="#ef3b36" font-size="30" font-family="Tahoma"  x="0" y="50">${locationText}</text>
    </svg>
    `;

  const locationTextSVGBuffer = Buffer.from(locationTextSVG);

  sharp(centerImagePath)
  .resize({width: 1000})
  .extract({ left: 0, top: 200, width: 1000, height: 850 })
  .toBuffer()
  .then(centerImage => {
    sharp(foodIconPath)
    .resize({ width: 45 })
    .toBuffer()
    .then(foodIcon => { 
      sharp(locationIconPath)
    .resize({ width: 45 })
    .toBuffer()
    .then(locationIcon => {
      sharp({
        create: {
          width: 1000,
          height: 1100,
          channels: 4,
          background: { r: 255, g: 255, b: 255 }
        }
      })
      .composite([
        {input: foodIcon, top: 30, left: 15},
        {input: foodTextSVGBuffer, top: 25, left: 80},
        {input: locationIcon, top: 1010, left: 15},
        {input: locationTextSVGBuffer, top: 1005, left: 80},
        {input: centerImage, gravity: 'center'},
        {input: logoPath, left: 750, top: 1000}
      ]).png().toFile(outputFilename)
      .then(data => {
        console.log('done!');
      }).catch(err => {
        throw err;
      });
    })
    .catch(err => {throw err});
    })
    .catch(err => { throw err });
  }).catch(err => {
    throw err;
  })

}

swotifyImage(centerImagePath, foodText, locationText, outputFilename, foodIconPath, locationIconPath, logoPath);
@saadanjum
Copy link
Author

I have traced the issue down to the composite function. It seemed that I can call the toFile function just fine if its a simple resize but after I call composite. even with a simple 1 image over base, I am getting the error. and that too only on my Ubuntu VM.

@lovell
Copy link
Owner

lovell commented Apr 17, 2022

Please ensure all of the input properties contain filenames that exist and have the relevant access permissions. As of the next release the error message will include the filename via #2360

@saadanjum
Copy link
Author

Thank you for such quick response. We need more active contributors like you in the community. I figured out the issue. IT was indeed one of the files. Except it was not missing but the filename in code was all small letters where as the actual filename was camel case. The reason it worked on my machine was because Mac's file system is case insensitive where as it is case sensitive on ubuntu. (a very very noob mistake on my behalf).
Closing the issue.

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

No branches or pull requests

2 participants