写真サイズ変更などを実現するのは、ImageMagicというツールの一つプログラムです。
CentOS(RedHat系)やUbuntu(Debian系)などのLinuxとも使えます。現在2023/7時点で、バージョン「6.9.11」が使えるようですが、最後の更新は2021年だったようです。
1.インストール
このソフトをCentOSとUbuntuでそれぞれのインストール仕方を下記通りメモします。
CentOS
♯ sudo yum -y install ImageMagick
Ubuntu
$ sudo apt-get install imagemagick
インストールするソフトはImageMagickですが、写真編集に使うコマンドは「Convert」となります。
$ which convert
/usr/bin/convert
$ convert --version
Version: ImageMagick 6.9.11-60 Q16 x86_64 2021-01-25 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP(4.5)
Delegates (built-in): bzlib djvu fftw fontconfig freetype heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png tiff webp wmf x xml zlib
2.写真サイズ変更
convertコマンドの機能は結構豊富です。サイズ変更は、以下のように実行すればよいです。詳細はman convertで調べてください。
$ convert -resize 160x picture_a.jpg picture_b.jpg
ちなみに、man convertで調べた結果の一部は以下となります。
$ man convert
NAME
convert - convert between image formats as well as resize an image, blur, crop, de-
speckle, dither, draw on, flip, join, re-sample, and much more.
SYNOPSIS
convert-im6.q16 [input-option] input-file [output-option] output-file
OVERVIEW
The convert-im6.q16 program is a member of the ImageMagick-ims6.q16(1) suite of tools.
Use it to convert between image formats as well as resize an image, blur, crop, de-
speckle, dither, draw on, flip, join, re-sample, and much more.
For more information about the convert command, point your browser to
file:///usr/share/doc/imagemagick-6-common/html/www/convert.html (on debian system you
may install the imagemagick-6 package) or https://www.imagemagick.org/script/convert.php.
3.実行例
左側「orignal.png」は編集対象写真で、右側「out.png」は編集後写真です。
実行したコマンドは以下となります。
$ convert -resize 160x orignal.png out.png
4.参照URL