获取图像的可用尺寸

huangapple go评论49阅读模式
英文:

Imagemagick - Getting the usable dimension of an image

问题

我有一个进程,它基于一些参数使用convert(ImageMagick)创建文件,然后检查文件并返回具有实际像素的最大尺寸。

命令如下:

convert -size 5000x5000 xc:white -font {font} -pointsize {size} -fill black -draw "{some_occassional_additional_parameter}text 200,2500 \"{text}\"" {some_other_occassional_additional_parameter}{temporary_file}
convert {temporary_file}.png -trim +repage -format "%[w]x%[h]\n" info:

它将产生类似于:526x425的结果。

这个进程每天运行50万次,似乎是一个巨大的瓶颈。我正在寻找一个可以在内存中完成的解决方案,不需要总是创建文件并检查它,而是以某种方式在内存中执行它。

如果能加速它,就像提高50%的速度,那将是一个巨大的成就。

谢谢!

英文:

I've a process which is creating a file with convert (ImageMagick) based on some parameter, and after that it checks the file and gives back the biggest dimension of it which has real pixels.

The commands look like this:

convert -size 5000x5000 xc:white -font {font} -pointsize {size} -fill black -draw "{some_occassional_additional_parameter}text 200,2500 \"{text}\"" {some_other_occassional_additional_parameter}{temporary_file}
convert {temporary_file}.png -trim +repage -format "%[w]x%[h]\n" info:

. It'll result something like: 526x425

This process runs half a million time per day, and it seems to be a huge bottleneck. I'm looking for a solution which can done this in memory, so not always creating a file and check it, but do it in memory somehow.

If can speed it up just like 50%, that'd be a huge achievement.

Thank You

答案1

得分: 0

将您的第一个命令更改为:

convert -size ... xc:... occasionalstuff  -format "%@" info:

请注意,您可以,而且可能应该,对"%@"进行双引号引用,特别是如果您使用包含对shell具有重要意义的字符的表达式,尽管在这种特定情况下,这并不是绝对必要的。

英文:

Not at a computer to test, but change your first command to:

convert -size ... xc:... occasionalstuff  -format "%@" info:

Note that you can, and probably should double quote the "%@" especially if you use expressions containing characters of significance to the shell, though it is not strictly necessary in this specific case.

huangapple
  • 本文由 发表于 2023年2月10日 03:39:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/75403644.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定