【问题标题】:Bash in mac and image magickMac 中的 Bash 和图像魔法
【发布时间】:2017-03-11 17:11:33
【问题描述】:

我在 osx mac 中有一个 .sh 用于在应用程序中生成图标上下文,但是当我运行脚本时我收到一条消息

convert: unable to open image `c.png': No such file or directory @ error/blob.c/OpenBlob/2709.
convert: unable to open file `c.png' @ error/png.c/ReadPNGImage/3917.
convert: no images defined `mipmap-mdpi/c.png' @ error/convert.c/ConvertImageCommand/3210.

文件 c.png 留在文件夹中

read original
read nombre_resultante
read size


Resize () {

  if [ "$size" == "1" ]; then
    SIZE_MDPI="48x48"
    SIZE_HDPI="72x72"
    SIZE_XHDPI="96x96"
    SIZE_XXHDPI="144x144"
    SIZE_XXXHDPI="192x192"
  elif [ "$size" == "2" ]; then
    SIZE_MDPI="24x24"
    SIZE_HDPI="36x36"
    SIZE_XHDPI="48x48"
    SIZE_XXHDPI="72x72"
    SIZE_XXXHDPI="96x96"
  fi

  rm -rf mipmap-mdpi/*
  rm -rf mipmap-hdpi/*
  rm -rf mipmap-xhdpi/*
  rm -rf mipmap-xxhdpi/*
  rm -rf mipmap-xxxhdpi/*

  convert $original -resize "$SIZE_MDPI" mipmap-mdpi/$nombre_resultante
  convert $original -resize "$SIZE_HDPI" mipmap-hdpi/$nombre_resultante
  convert $original -resize "$SIZE_XHDPI" mipmap-xhdpi/$nombre_resultante
  convert $original -resize "$SIZE_XXHDPI" mipmap-xxhdpi/$nombre_resultante
  convert $original -resize "$SIZE_XXXHDPI" mipmap-xxxhdpi/$nombre_resultante
}

Resize $size

【问题讨论】:

  • 您确定该文件存在吗?您可以在运行命令之前在 bash 中预先检查它。并且您的 $size 参数在调用 Resize 时没有用

标签: bash macos imagemagick imagemagick-convert


【解决方案1】:

错误信息表示文件c.png 不存在。我可以使用不存在的文件重现您的错误消息:

$ convert nonexistent.png -resize 48x48 a/b/whatever.png
convert: unable to open image `nonexistent.png': No such file or directory @ error/blob.c/OpenBlob/2702.
convert: unable to open file `nonexistent.png' @ error/png.c/ReadPNGImage/3913.
convert: no images defined `a/b/whatever.png' @ error/convert.c/ConvertImageCommand/3241.

运行脚本时,您可能位于错误的目录中。 cd 到文件所在的正确目录,以及子目录mipmap-*dpi 所在的位置。

您可以在调用调整大小函数之前添加一个检查,如下所示:

if [ ! -f "$original" ]; then
    echo fatal: file does not exist: $original
    exit 1
fi

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多