There are three types of operation in this section.
First, vips_affine() applies an affine transform to an image. This is any
sort of 2D transform which preserves straight lines; so any combination of
stretch, sheer, rotate and translate. You supply an interpolator for it to
use to generate pixels, see vips_interpolate_new(). It will not produce
good results for very large shrinks: you'll see aliasing.
vips_reduce() is like vips_affine(), but it can only shrink images, it can't
enlarge, rotate, or skew. It's very fast and uses an adaptive kernel for
interpolation.
vips_shrink() is a fast block shrinker. It can quickly reduce images by
large integer factors. It will give poor results for small size reductions:
again, you'll see aliasing.
Next, vips_resize() specialises in the common task of image reduce and
enlarge. It strings together combinations of vips_shrink(), vips_reduce(),
vips_affine() and others to implement a general, high-quality image
resizer.
Finally, vips_mapim() can apply arbitrary 2D image transforms to an image.
Shrink in
by a pair of factors with a simple box filter. For non-integer
factors, vips_shrink() will first shrink by the integer part with a box
filter, then use vips_reduce() to shrink by the
remaining fractional part.
This is a very low-level operation: see vips_resize() for a more
convenient way to resize images.
This operation does not change xres or yres. The image resolution needs to
be updated by the application.
Make a thumbnail from a file. Shrinking is done in three stages: using any
shrink-on-load features available in the file import library, using a block
shrink, and using a lanczos3 shrink. At least the final 200% is done with
lanczos3. The output should be high quality, and the operation should be
quick.
The output image will fit within a square of size width
x width
. You can
specify a separate height with the height
option.
If you set crop
, then the output image will fill the whole of the width
x
height
rectangle, with any excess cropped away. See vips_smartcrop() for
details on the cropping strategy.
Normally the operation will upsize or downsize as required to fit the image
inside or outside the target size. If size
is set
to VIPS_SIZE_UP, the operation will only upsize and will just
copy if asked to downsize.
If size
is set
to VIPS_SIZE_DOWN, the operation will only downsize and will just
copy if asked to upsize.
If size
is VIPS_SIZE_FORCE, the image aspect ratio will be broken and the
image will be forced to fit the target.
Normally any orientation tags on the input image (such as EXIF tags) are
interpreted to rotate the image upright. If you set no_rotate
to TRUE,
these tags will not be interpreted.
Shrinking is normally done in sRGB colourspace. Set linear
to shrink in
linear light colourspace instead. This can give better results, but can
also be far slower, since tricks like JPEG shrink-on-load cannot be used in
linear space.
If you set export_profile
to the filename of an ICC profile, the image
will be transformed to the target colourspace before writing to the
output. You can also give an import_profile
which will be used if the
input image has no ICC profile, or if the profile embedded in the
input image is broken.
Use intent
to set the rendering intent for any ICC transform. The default
is VIPS_INTENT_RELATIVE.
This operator calls vips_affine() for you, calculating the matrix for the
affine transform from scale
and angle
. Other parameters are passed on to
vips_affine() unaltered.
This operator calls vips_affine() for you, calculating the matrix for the
affine transform from scale
and angle
. Other parameters are passed on to
vips_affine() unaltered.
The section of the output space defined by oarea
is written to
out
. oarea
is a four-element int array of left, top, width, height.
By default oarea
is just large enough to cover the whole of the
transformed input image.
By default, new pixels are filled with background
. This defaults to
zero (black). You can set other extend types with extend
. VIPS_EXTEND_COPY
is better for image upsizing.
interpolate
defaults to bilinear.
idx
, idy
, odx
, ody
default to zero.
This operation does not change xres or yres. The image resolution needs to
be updated by the application.
When downsizing, the
image is block-shrunk with vips_shrink(),
then the image is shrunk again to the
target size with vips_reduce(). How much is done by vips_shrink() vs.
vips_reduce() varies with the kernel
setting. Downsizing is done with
centre convention.
vips_resize() normally uses VIPS_KERNEL_LANCZOS3 for the final reduce, you
can change this with kernel
.
When upsizing (scale
> 1), the operation uses vips_affine() with
a VipsInterpolate selected depending on kernel
. It will use
VipsInterpolateBicubic for VIPS_KERNEL_CUBIC and above. It adds a
0.5 pixel displacement to the input pixels to get centre convention scaling.
vips_resize() normally maintains the image aspect ratio. If you set
vscale
, that factor is used for the vertical scale and scale
for the
horizontal.
If either axis would drop below 1px in size, the shrink in that dimension
is limited. This breaks the image aspect ratio, but prevents errors due to
fractional pixel sizes.
This operation does not change xres or yres. The image resolution needs to
be updated by the application.
This operator resamples in
using index
to look up pixels. out
is
the same size as index
, with each pixel being fetched from that position in
in
. That is:
1
out[x,y]=in[index[x,y]]
If index
has one band, that band must be complex. Otherwise, index
must
have two bands of any format.
Coordinates in index
are in pixels, with (0, 0) being the top-left corner
of in
, and with y increasing down the image. Use vips_xyz() to build index
images.
interpolate
defaults to bilinear.
This operation does not change xres or yres. The image resolution needs to
be updated by the application.
See vips_maplut() for a 1D equivalent of this operation.