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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:52:34  来源:igfitidea点击:

Error for convert command in command line

macosbashshell

提问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

要遵循的步骤

install using command$ sudo port install ImageMagickor using Homebrew command brew install imagemagickor 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 的帮助下完成它——这是一个非常好的和流行的包管理器

  1. To Install homeBrew past in your terminal

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. To install imagemagick past in the terminal

    brew install imagemagick

  1. 在终端中安装 homeBrew 过去

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  2. 在终端中安装 imagemagick past

    brew 安装 imagemagick

回答by Matteo

convertis part of ImageMagickwhich is not installed by default on OS X.

convertImageMagick 的一部分,默认情况下未安装在 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 并直接安装它