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

imagemagick not working on google cloud function #607

Open
asad-arthur opened this issue May 7, 2024 · 0 comments
Open

imagemagick not working on google cloud function #607

asad-arthur opened this issue May 7, 2024 · 0 comments

Comments

@asad-arthur
Copy link

asad-arthur commented May 7, 2024

I am using this npm package for image-magick and using google cloud functions framework to be used with my package.

the package that google cloud function are using for image magick as mentioned in their docs https://cloud.google.com/appengine/docs/standard/reference/system-packages?tab=node.js#top, this doesn't work.

I am creating a simple function to download a file and then convert that pdf file to png file using this code

import * as util from "util";
import fs from "fs";

import * as im from "imagemagick";
import * as child_process from "child_process";
import functions from "@google-cloud/functions-framework";
import { CloudProvider } from "./packages/cloud-provider/src/index.js";

const { execFileSync, spawnSync, execSync } = child_process;

const cloud = CloudProvider.getInstance();

functions.http("im-testing", async (req, res) => {
  let val = await cloud.storage.getFile(
    "gcp-setup-testing",
    "asad-testing/pdf-test.pdf"
  );
  const output1 = execSync("ls ./temp").toString();
  console.log("before: ", output1);
  fs.writeFileSync("./temp/pdf-test.pdf", val?.Body);
  if (fs.existsSync("./temp/pdf-test.pdf")) {
    execSync('chmod 755 ./temp/pdf-test.pdf');
  }
  
  let convert = util.promisify(im.convert);
  let convArr = [
    "-density",
    "400",
    "./temp/pdf-test.pdf",
    "-resize",
    "25%",
    "./temp/a.png",
  ];
  await convert(convArr);
  const output2 = execSync("ls ./temp").toString();
  console.log("after: ", output2);
  res.status(200).json({ message: "File converted successfully" });
});

I always get this error Command failed: convert-im6.q16: no images defined ./temp/a.png' @
error/convert.c/ConvertImageCommand/3229.`

I made a docker container using this

FROM node:20.9.0
# Install ImageMagick
RUN apt-get update -y && \
    apt-get install -y imagemagick
WORKDIR /usr/src/app

COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build-ts
CMD ["npm", "run", "start-ts"]

but the max version that container allows for imagemagick is 6.9.11 and that isn't working.
I tried running a simple command for convert that also gave me the same error. Let me know if you need any other log or information on this one but the imagemagick v6.9.11 isn't working anymore on google cloud function

@HKWinterhalter HKWinterhalter removed their assignment Jun 3, 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

2 participants