Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image Resizing #97

Closed
onur-ozkan opened this issue Sep 12, 2020 · 7 comments
Closed

Image Resizing #97

onur-ozkan opened this issue Sep 12, 2020 · 7 comments
Labels
question Further information is requested

Comments

@onur-ozkan
Copy link

onur-ozkan commented Sep 12, 2020

According to docs, there is a Resize function that changes image dimensions based on scale ratio. But what if I want to change dimensions by giving width and height values, which function should I use?

@onur-ozkan
Copy link
Author

I try

var image = Image.Thumbnail(Filename, 300, height: 300);
that one but the output's height is not correct.

@kleisauke
Copy link
Owner

Did you see #71 (comment)?

@kleisauke kleisauke added the question Further information is requested label Sep 14, 2020
@lofcz
Copy link

lofcz commented Sep 17, 2020

This: ThumbnailImage(w, h, size: "force");

@onur-ozkan
Copy link
Author

This: ThumbnailImage(w, h, size: "force");

Thanks!

@kleisauke
Copy link
Owner

I'd avoid ThumbnailImage, if possible. It can't do any of the shrink-on-load tricks, so it's much, much slower. The "force" parameter (VIPS_SIZE_FORCE) breaks aspect ratio, so I can't recommend that either.

@Darkle
Copy link
Contributor

Darkle commented Jul 22, 2023

I'd avoid ThumbnailImage, if possible. It can't do any of the shrink-on-load tricks, so it's much, much slower. The "force" parameter (VIPS_SIZE_FORCE) breaks aspect ratio, so I can't recommend that either.

What would be the thing to use in its place?

Oh wait, I see in the examples that it mentions to use ThumbnailBuffer: https://github.com/kleisauke/net-vips/blob/master/samples/NetVips.Samples/Samples/ThumbnailPipeline.cs#L211

@kleisauke
Copy link
Owner

What would be the thing to use in its place?

You can use the various Image.Thumbnail* functions for this. For example:

-using var image = Image.NewFromFile(Filename, access: Enums.Access.Sequential);
-
 // `vips_thumbnail` resize behavior is based on a square bounding box.
 // To resize along a specific axis, pass a huge value to the opposite axis.
 // See: https://github.com/libvips/libvips/pull/1639
-using var thumb = image.ThumbnailImage(300, height: 10000000);
+using var thumb = Image.Thumbnail(Filename, 300, height: 10000000);
 thumb.WriteToFile("thumbnail.jpg");
-using var image = Image.NewFromBuffer(Buffer, access: Enums.Access.Sequential);
-using var thumb = image.ThumbnailImage(300, height: 10000000);
+using var thumb = Image.ThumbnailBuffer(Buffer, 300, height: 10000000);
 thumb.WriteToFile("thumbnail.jpg");
-using var image = Image.NewFromStream(Stream, access: Enums.Access.Sequential);
-using var thumb = image.ThumbnailImage(300, height: 10000000);
+using var thumb = Image.ThumbnailStream(Stream, 300, height: 10000000);
 thumb.WriteToFile("thumbnail.jpg");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants