1.0.13 • Published 9 months ago

img-convertor v1.0.13

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

img-convertor

img-convertor is a command-line tool based on Node.js and the Sharp library for batch image conversion and resizing. It supports various image formats and can recursively process all images in the specified directory.

Installation

Before using this tool, ensure that Node.js and npm are installed. Then run the following command to install the tool globally:

npm install -g img-convertor

Usage

This tool provides two main commands: converter and resize.

1. Convert Image Formats

Use the converter command to convert the format of all images in a directory:

converter <sourceTypes> <targetType>
  • <sourceTypes>: The source image formats to convert (e.g., png,jpg,jpeg). Optional, defaults to png,jpg,jpeg,webp,gif,bmp.
  • <targetType>: The target image format (e.g., png, jpeg, webp). Optional, defaults to png.

Example:

converter jpg png

Converts all .jpg images in the current directory to .png format and saves them in the output directory.

2. Resize Images

Use the resize command to resize images:

resize <sourceTypes> <targetType> <width> <height>
  • <sourceTypes>: The source image formats to resize (e.g., png,jpg,jpeg). Optional, defaults to png,jpg,jpeg,webp,gif,bmp.
  • <targetType>: The target image format (e.g., png, jpeg, webp). Optional, defaults to png.
  • <width> and <height>: Specify the target width and height of the images in pixels.

Example:

resize jpg png 800 600

Converts all .jpg images in the current directory to .png format, resizes them to 800x600 pixels, and saves them in the output directory.

Supported Image Formats

  • Input formats: png, jpg, jpeg, webp, gif, bmp.
  • Output formats: jpeg, png, webp, tiff, gif, avif, svg.

Notes

  • The converted or resized images will be saved in the output folder in the current directory.
  • If <sourceTypes> and <targetType> are not provided, the program will use default values.
  • For resizing images, both width and height parameters are required.

Dependencies

This tool is built on the sharp library. Please ensure your environment supports this library.

img-convertor

img-convertor 是一个基于 Node.js 和 Sharp 库的命令行工具,用于批量转换和调整图像大小。它支持多种图像格式,并且可以递归处理指定目录中的所有图片。

安装

在使用前,请确保已安装 Node.jsnpm,然后执行以下命令来全局安装此工具:

npm install -g img-convertor

使用方法

该工具提供两个主要命令:converterresize

1. 转换图片格式

使用 converter 命令转换目录中的所有图片格式:

converter <sourceTypes> <targetType>
  • <sourceTypes>:要转换的源图像格式(例如:png,jpg,jpeg)。可选,默认支持 png,jpg,jpeg,webp,gif,bmp
  • <targetType>:目标图像格式(例如:pngjpegwebp 等)。可选,默认为 png

示例:

converter jpg png

将当前目录中的所有 .jpg 图片转换为 .png 格式,并保存在 output 目录中。

2. 调整图片大小

使用 resize 命令调整图片大小:

resize <sourceTypes> <targetType> <width> <height>
  • <sourceTypes>:要调整大小的源图像格式(例如:png,jpg,jpeg)。可选,默认支持 png,jpg,jpeg,webp,gif,bmp
  • <targetType>:目标图像格式(例如:pngjpegwebp 等)。可选,默认为 png
  • <width><height>:指定目标图片的宽度和高度,单位为像素。

示例:

resize jpg png 800 600

将当前目录中的所有 .jpg 图片转换为 .png 格式,并调整大小为 800x600 像素,结果保存在 output 目录中。

支持的图像格式

  • 输入格式:pngjpgjpegwebpgifbmp
  • 输出格式:jpegpngwebptiffgifavifsvg

注意事项

  • 目标图片会被保存在当前目录下的 output 文件夹中。
  • 在转换或调整大小时,如果没有提供 <sourceTypes><targetType>,程序会使用默认值。
  • 调整图片大小时,必须提供宽度和高度参数。

依赖

本工具基于 sharp 库开发,请确保您的环境支持此库。

1.0.10

9 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.13

9 months ago

1.0.4

10 months ago

1.0.12

9 months ago

1.0.3

10 months ago

1.0.1

10 months ago