bash 命令行中转换命令的错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28627473/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Error for convert command in command line
提问by Nevin Raj Victor
I have a bash shell script as below.
我有一个 bash shell 脚本,如下所示。
#!/bin/bash
SIZES=("512" "1024" "2048")
for i in ${!SIZES[*]}
do
SIZE=${SIZES[$i]}
echo $SIZE
# first, resize original image
convert -resize $SIZE"x"$SIZE! chernarus2048.jpg chernarus$SIZE"x"$SIZE.jpg
mkdir tiles$SIZE
# slice resized image into 256x256 tiles
convert -crop 256x256 chernarus$SIZE"x"$SIZE.jpg tiles$SIZE/tile%04d.jpg
rm chernarus$SIZE"x"$SIZE.jpg
done
But When I run this in command line using the following command
但是当我使用以下命令在命令行中运行它时
sh generate_tiles.sh chernarus2048.jpg
I am getting an error convert: command not found
我收到一个错误转换:找不到命令
I am using OS X Yosemite 10.10.2.The image is kept in the same folder where the shell script is placed.Please help me out.
我正在使用 OS X Yosemite 10.10.2。图像保存在放置 shell 脚本的同一文件夹中。请帮帮我。
采纳答案by Anshad Rasheed
Steps to follow
要遵循的步骤
- Confirm macportis installed for reference https://www.macports.org/install.php
- Then install imagemagick using any of the following method
- 确认macport已安装以供参考 https://www.macports.org/install.php
- 然后使用以下任何一种方法安装 imagemagick
install using command$ sudo port install ImageMagick
or using Homebrew command brew install imagemagick
or download from the link http://cactuslab.com/imagemagick/
使用命令$ sudo port install ImageMagick
或使用 Homebrew 命令安装brew install imagemagick
或从链接http://cactuslab.com/imagemagick/下载
- Then close your terminal and restart the pc and run your code again.
- 然后关闭您的终端并重新启动电脑并再次运行您的代码。
回答by Nikolay Shubenkov
You can also make it with help of Homebrew- which is quite nice and popular package manager
你也可以在Homebrew 的帮助下完成它——这是一个非常好的和流行的包管理器
To Install homeBrew past in your terminal
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
To install imagemagick past in the terminal
brew install imagemagick
在终端中安装 homeBrew 过去
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
在终端中安装 imagemagick past
brew 安装 imagemagick
回答by Matteo
convert
is part of ImageMagickwhich is not installed by default on OS X.
convert
是ImageMagick 的一部分,默认情况下未安装在 OS X 上。
From the download instructionson the ImageMagick site:
从ImageMagick 站点上的下载说明:
- Install MacPorts
Install ImageMagick with
$ sudo port install ImageMagick
- 安装MacPorts
安装 ImageMagick
$ sudo port install ImageMagick
回答by dqshll
port install not work for me. it always return "Error: Port ImageMagick not found" if you failed installing with port, you can download pkg and install it directly from http://cactuslab.com/imagemagick/
端口安装对我不起作用。如果使用端口安装失败,它总是返回“错误:找不到端口 ImageMagick”,您可以从http://cactuslab.com/imagemagick/下载 pkg 并直接安装它