I have image with dimension 900x500 and I want to resize it to new image dimension 150x150 so the full image will fit on the size of the canvas and will put center.
I do it in ImageMagick like this:
convert a.png -resize 150x150\> -size 150x150 xc:white +swap -gravity center -composite a.jpg
How to do it in VIPS?
I only try like this
vipsthumbnail a.png --size 150x150 -o a.jpg
Hello, you'd have to do it in two steps at the command-line:
vipsthumbnail a.png -o t1.v -s 150
vips gravity t1.v b.jpg centre 150 150 --extend white
That's using t1.v as a temporary intermediate file.
If you use Python / Ruby / PHP / node / etc. you can do it without the intermediate.
@jcupitt wow thank you it works like a charm :)
BTW I want to use via PHP on my CentOS 7 machine, but I tried pecl install vips
But it failed due to I can't install libvips-devel
php-vips will be difficult on centos7. It ships with php5.4, but php-vips is php7+ only.
You'll need to update your php a lot, or use a more recent platform.
FYI:
If you're running Centos >= 7 then there's an easier way to install libvips (v8.6.3) and the PHP vips (v1.0.8) extension (the Remi repository provides a easy way to install it).
# Install the EPEL repository configuration package:
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# Install the Remi repository configuration package:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
# Install the yum-utils package (for the yum-config-manager command):
yum install yum-utils
# Command to enable the repository (PHP 7.2.4, for PHP 7.1.16 use: remi-php71):
yum-config-manager --enable remi-php72
# Install libvips and the PHP vips extension:
yum install php-pecl-vips
Most helpful comment
FYI:
If you're running Centos >= 7 then there's an easier way to install libvips (v8.6.3) and the PHP vips (v1.0.8) extension (the Remi repository provides a easy way to install it).