Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /usr/share/gtk-doc/html/libvips/ drwxr-xr-x | |
| Viewing file: Select action/file-type:
libvips ships with a handy command-line image thumbnailer,
The thumbnailing functionality is implemented by
$filename = "image.jpg";
$image = Vips\Image::thumbnail($filename, 200, ["height" => 200]);
$image->writeToFile("my-thumbnail.jpg");
libvips options
Looping
$ vipsthumbnail *.jpg will make a thumbnail for every jpeg in the current directory. See the Output directory section below to see how to change where thumbnails are written.
$ parallel vipsthumbnail ::: *.jpg Thumbnail size
You can set the bounding box of the generated thumbnail with the $ vipsthumbnail shark.jpg --size 200x100 Use a single number to set a square bounding box. You can omit either number but keep the x to mean resize just based on that axis, for example: $ vipsthumbnail shark.jpg --size 200x Will resize to 200 pixels across, no matter what the height of the input image is.
You can append
You can append Cropping
$ vipsthumbnail owl.jpg --smartcrop attention -s 128
Where Gives this result:
First it shrinks the image to get the vertical axis to 128 pixels, then crops down to 128 pixels across using the Linear lightShrinking images involves combining many pixels into one. Arithmetic averaging really ought to be in terms of the number of photons, but (for historical reasons) the values stored in image files are usually related to the voltage that should be applied to the electron gun in a CRT display.
$ vipsthumbnail fred.jpg --linear
The downside is that in linear mode, none of the very fast shrink-on-load tricks that For example, for a 10,000 x 10,000 pixel JPEG I see: $ time vipsthumbnail wtc.jpg real 0m0.317s user 0m0.292s sys 0m0.016s $ time vipsthumbnail wtc.jpg --linear real 0m4.660s user 0m4.640s sys 0m0.016s Output directory
You set the thumbnail write parameters with the $ vipsthumbnail fred.jpg jim.tif -o tn_%s.jpg
For each of the files to be thumbnailed,
If the pattern given to $ vipsthumbnail fred.jpg ../jim.tif -o /mythumbs/tn_%s.jpg
Now both thumbnails will be written to
Conversely, if $ vipsthumbnail fred.jpg ../jim.tif -o mythumbs/tn_%s.jpg Now both input files will have thumbnails written to a subdirectory of their current directory. Output format and options
You can use $ vipsthumbnail fred.jpg ../jim.tif -o tn_%s.png Will write thumbnails in PNG format. You can give options to the image write operation as a list of comma-separated arguments in square brackets. For example: $ vipsthumbnail fred.jpg ../jim.tif -o tn_%s.jpg[Q=90,optimize_coding] will write jpeg images with quality 90, and will turn on the libjpeg coding optimizer. Check the image write operations to see all the possible options. For example:
$ vips jpegsave
save image to jpeg file
usage:
jpegsave in filename
where:
in - Image to save, input VipsImage
filename - Filename to save to, input gchararray
optional arguments:
Q - Q factor, input gint
default: 75
min: 1, max: 100
profile - ICC profile to embed, input gchararray
optimize-coding - Compute optimal Huffman coding tables, input gboolean
default: false
interlace - Generate an interlaced (progressive) jpeg, input gboolean
default: false
no-subsample - Disable chroma subsample, input gboolean
default: false
trellis-quant - Apply trellis quantisation to each 8x8 block, input gboolean
default: false
overshoot-deringing - Apply overshooting to samples with extreme values, input gboolean
default: false
optimize-scans - Split the spectrum of DCT coefficients into separate scans, input gboolean
default: false
quant-table - Use predefined quantization table with given index, input gint
default: 0
min: 0, max: 8
strip - Strip all metadata from image, input gboolean
default: false
background - Background value, input VipsArrayDouble
The For example: $ vipsthumbnail 42-32157534.jpg $ ls -l tn_42-32157534.jpg -rw-r–r– 1 john john 6682 Nov 12 21:27 tn_42-32157534.jpg
$ vipsthumbnail 42-32157534.jpg -o x.jpg[optimize_coding,strip] $ ls -l x.jpg -rw-r–r– 1 john john 3600 Nov 12 21:27 x.jpg Colour management
For example: $ vipsthumbnail shark.jpg $ ls -l tn_shark.jpg -rw-r–r– 1 john john 7295 Nov 9 14:33 tn_shark.jpg Now encode with sRGB and delete any embedded profile: $ vipsthumbnail shark.jpg --eprofile /usr/share/color/icc/sRGB.icc --delete $ ls -l tn_shark.jpg -rw-r–r– 1 john john 4229 Nov 9 14:33 tn_shark.jpg It’ll look identical to a user, but be almost half the size. You can also specify a fallback input profile to use if the image has no embedded one. This can often happen with CMYK images, producing an error message like: $ vipsthumbnail kgdev.jpg vipsthumbnail: unable to thumbnail kgdev.jpg vips_colourspace: no known route from 'cmyk' to 'srgb' If you supply a CMYK profile, it will be able to convert the image, for example: $ vipsthumbnail kgdev.jpg --iprofile /usr/share/color/icc/colord/FOGRA28L_webcoated.icc I’ve had good results with this profile: https://github.com/libvips/nip2/blob/master/share/nip2/data/cmyk.icm It makes nice-looking images from most CMYK files, and is completely free. Auto-rotateMany JPEG files have a hint set in the header giving the image orientation. If you strip out the metadata, this hint will be lost, and the image will appear to be rotated.
If you use the |
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0053 ]-- |