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 hangs 😞 #271

Open
reggi opened this issue May 9, 2024 · 1 comment
Open

imagemagick hangs 😞 #271

reggi opened this issue May 9, 2024 · 1 comment

Comments

@reggi
Copy link

reggi commented May 9, 2024

I have a command here:

convert -background white -font "/System/Library/Fonts/Supplemental/Comic Sans MS.ttf" -pointsize 30 label:meow  png:- | identify -format "%w" -
77

For some reason this just hangs:

#!/usr/bin/env -S deno run --allow-all
import $ from "@david/dax"; // "dax-sh" in Node

async function getImageWidth(opts: {
  font: string;
  fontSize: number;
  text: string;
  trim?: boolean;
}) {
  const { font, fontSize, text, trim } = opts;
  const shouldTrim = trim ? "-trim" : "";
  return await $`convert -background white -font ${font} -pointsize ${fontSize} label:${text} ${shouldTrim} png:- | identify -format "%w" -`.text();
}

console.log(
  await getImageWidth({
    font: "/System/Library/Fonts/Supplemental/Comic Sans MS.ttf",
    fontSize: 30,
    text: "meow",
  })
);
@NfNitLoop
Copy link
Contributor

I expect this line might not be operating as you expect:

  const shouldTrim = trim ? "-trim" : "";

Later, you insert ${shouldTrim} into the command.

Coming from shells like Bash, you're probably expecting that empty string to disappear and have no effect. But dax automatically quotes all arguments, so you're still ending up with a "" or '' in the arguments getting passed to convert.

Try enabling verbose command logging like this to verify:

$.setPrintCommand(true)

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