NewThumbnail creates new thumbnail with resize and crop from imagor.Blob
( ctx context.Context, blob *imagor.Blob, width, height int, crop vips.Interesting, size vips.Size, n, page int, dpi int, )
| 332 | |
| 333 | // NewThumbnail creates new thumbnail with resize and crop from imagor.Blob |
| 334 | func (v *Processor) NewThumbnail( |
| 335 | ctx context.Context, blob *imagor.Blob, width, height int, crop vips.Interesting, |
| 336 | size vips.Size, n, page int, dpi int, |
| 337 | ) (*vips.Image, error) { |
| 338 | var options = &vips.LoadOptions{} |
| 339 | if dpi > 0 { |
| 340 | options.Dpi = dpi |
| 341 | } |
| 342 | if blob != nil { |
| 343 | switch blob.BlobType() { |
| 344 | case imagor.BlobTypeAVIF, imagor.BlobTypeHEIF: |
| 345 | options.Thumbnail = true |
| 346 | } |
| 347 | } |
| 348 | options.Unlimited = v.Unlimited && unlimitedSupportedByLoader(blob) |
| 349 | var err error |
| 350 | var img *vips.Image |
| 351 | if isMultiPage(blob, n, page) { |
| 352 | applyMultiPageOptions(options, n, page) |
| 353 | if crop == vips.InterestingNone || size == vips.SizeForce { |
| 354 | if img, err = v.newImageFromBlob(ctx, blob, options); err != nil { |
| 355 | return nil, WrapErr(err) |
| 356 | } |
| 357 | if n > 1 || page > 1 { |
| 358 | // reload image to restrict frames loaded |
| 359 | n, page = recalculateImage(img, n, page) |
| 360 | return v.NewThumbnail(ctx, blob, width, height, crop, size, -n, -page, dpi) |
| 361 | } |
| 362 | if _, err = v.CheckResolution(img, nil); err != nil { |
| 363 | return nil, err |
| 364 | } |
| 365 | if err = img.ThumbnailImage(width, &vips.ThumbnailImageOptions{ |
| 366 | Height: height, Size: size, Crop: crop, |
| 367 | }); err != nil { |
| 368 | img.Close() |
| 369 | return nil, WrapErr(err) |
| 370 | } |
| 371 | } else { |
| 372 | if img, err = v.CheckResolution(v.newImageFromBlob(ctx, blob, options)); err != nil { |
| 373 | return nil, WrapErr(err) |
| 374 | } |
| 375 | if n > 1 || page > 1 { |
| 376 | // reload image to restrict frames loaded |
| 377 | n, page = recalculateImage(img, n, page) |
| 378 | return v.NewThumbnail(ctx, blob, width, height, crop, size, -n, -page, dpi) |
| 379 | } |
| 380 | if err = v.animatedThumbnailWithCrop(img, width, height, crop, size); err != nil { |
| 381 | img.Close() |
| 382 | return nil, WrapErr(err) |
| 383 | } |
| 384 | } |
| 385 | } else { |
| 386 | switch blob.BlobType() { |
| 387 | case imagor.BlobTypeJPEG, imagor.BlobTypeGIF, imagor.BlobTypeWEBP, |
| 388 | imagor.BlobTypeAVIF, imagor.BlobTypeHEIF: |
| 389 | // Use libvips thumbnail-source loaders when the format supports it. |
| 390 | img, err = v.newThumbnailFromBlob(ctx, blob, width, height, crop, size, options) |
| 391 | default: |