如果您需要将图像从一种格式转换为另一种格式,您可以使用GIMP来执行此操作,但有一种更简单的方法。您可以使用ImageMagick,它提供了一种使用命令行转换图像的方法。
安装 ImageMagick
ImageMagick可能已经安装。您可以签入Synaptic 包管理器(Synaptic Package Manager)。选择Administration | Synaptic Package Manager系统(System)菜单中的突触软件包管理器。
在Synaptic Package Manager窗口的(Synaptic Package Manager)快速搜索(Quick search)编辑框中,输入imagemagick。当您键入搜索词时,搜索结果开始显示。如果已经安装了ImageMagick,程序名称旁边的复选框将被填充为绿色,您可以跳到下面的使用 ImageMagick 转换图像(Converting an Image Using ImageMagick)部分。
如果尚未安装ImageMagick,请单击复选框以打开弹出菜单。从菜单中选择标记安装(Mark for Installation)选项。
一个黄色箭头显示在imagemagick(imagemagick)旁边的复选框上,表示它已标记为安装。单击应用(Apply)按钮继续安装。
将显示一个摘要(Summary)屏幕,其中列出了将要进行的所有更改。单击应用(Apply)按钮。
显示安装进度。
安装完成后将显示“已应用更改(Changes applied)”对话框。单击关闭(Close)按钮。
从File菜单中选择Quit以关闭Synaptic Package Manager。
使用 ImageMagick(Using ImageMagick)转换图像
安装ImageMagick后(ImageMagick),只需在终端窗口中使用 convert 命令。例如,以下命令会将PNG文件转换为JPEG文件。
$ convert sample.png sample.jpg
但是,将图像转换为JPEG会因文件大小而牺牲图像质量。有一个命令开关–quality,可让您指定生成的.jpg文件的质量。您可以设置一个介于0(最差质量)到100(最高质量)之间的值。请记住,质量越好(数字越高),文件越大。一般来说, (Generally)60到80之间的值对于大多数用途来说已经足够了。
以下命令将 sample.png 转换为质量为80的(80)JPEG图像。
$ convert –quality 80 sample.png sample.jpg
在与原始.png(.png)文件相同的目录中创建一个名为sample.jpg的JPEG文件。有一种快速的方法可以查看转换后的图像。Ubuntu中的默认图像查看器称为Eye of Gnome。使用Gnome 之眼(Eye of Gnome),您可以快速查看以下图像:ani、bmp、gif、ico、jpeg、pcx、png、pnm、ras、svg、tga、tiff、wbmp、xbm和xpm。
要从命令行运行Eye of Gnome,只需键入eog。因此,要查看转换后的图像文件,请键入以下命令:
$ eog sample.jpg
查看器打开并显示指定的图像。
要关闭Eye of Gnome ,请从文件(File)菜单中选择关闭。(Close)
如果您更喜欢使用命令行来执行任务,请单击此处(here)访问一个网页,该网页提供了一组从命令行使用ImageMagick的示例。(ImageMagick)享受!
Convert Images Between Formats via the Command Line in Ubuntu
If you need to convert an image from one format tо another you cаn use GIMP to do so, but there is an easier way. You can use ImageMagick, which provides a way to convert images using the command line.
Installing ImageMagick
ImageMagick may already be installed. You can check in the Synaptic Package Manager. Select Administration | Synaptic Package Manager from the System menu.
In the Quick search edit box on the Synaptic Package Manager window, enter imagemagick. The results of the search start to display as you type your search term. If ImageMagick is already installed, the check box next to the program name will be filled in green, and you can skip to the Converting an Image Using ImageMagick section below.
If ImageMagick is not already installed, click on the check box to open a pop-up menu. Select the Mark for Installation option from the menu.
A yellow arrow displays over the check box next to imagemagick, indicating it is marked for installation. Click the Apply button to continue with the installation.
A Summary screen displays listing all the changes that will be made. Click the Apply button.
The installation progress displays.
The Changes applied dialog box displays when the installation is finished. Click the Close button.
Select Quit from the File menu to close the Synaptic Package Manager.
Converting an Image Using ImageMagick
Once ImageMagick is installed, simply use the convert command in a terminal window. For example, the following command will convert a PNG file to a JPEG file.
$ convert sample.png sample.jpg
However, converting an image into a JPEG sacrifices image quality for file size. There is a command switch, –quality, that allows you to specify the quality of the resulting .jpg file. You can set a value between 0 (poorest quality) to 100 (highest quality). Remember that the better the quality (the higher the number), the bigger the file size. Generally, a value between 60 and 80 is good enough for most uses.
The following command converts sample.png into a JPEG image with a quality of 80.
$ convert –quality 80 sample.png sample.jpg
A JPEG file called sample.jpg is created in the same directory as the original .png file. There is a quick way to view the converted image. The default image viewer in Ubuntu is called Eye of Gnome. Using Eye of Gnome, you can quickly view the following images: ani, bmp, gif, ico, jpeg, pcx, png, pnm, ras, svg, tga, tiff, wbmp, xbm, and xpm.
To run Eye of Gnome from the command line, simply type eog. So, to view the converted image file type the following command:
$ eog sample.jpg
The viewer opens displaying the specified image.
To close Eye of Gnome, select Close from the File menu.
If you prefer using the command line to perform tasks, click here to access a web page that provides a set of examples using ImageMagick from the command line. Enjoy!