Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I achieved to resize my images using the package image

What I want to achieve is a conditional statement that reduces the size of the image if image is > than max (1920) and dont resize it otherwise.

This is my code:

 Widget build(BuildContext context) {
    void uploadImage(File result) async {
      var image = decodeImage(result.readAsBytesSync());
      var thumbnail = copyResize(image, width: 1920);
      var encoded = base64.encode(encodeJpg(thumbnail));
      var userAccount =
          await context.api.customersApi.accounts.uploadProfileImage(defaultOrganisationId, context.blocs.auth.state.user.id, ImageUploadRequest(encoded));

      // update the current user
      context.blocs.auth.updateUserAccount(userAccount.data);

    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
290 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can check the width and height of the image:

if (image.width > 1920 || image.height > 1920) {
    thumbnail = copyResze(image, width: 1920, height: 1920);
}
else {
    thumbnail = image;
}

I'm assuming you care mostly about the file size (~ area) of the image, though you should have no problem changing it to look at only one coordinate.

I might also note that a 1920 pixels wide image no longer qualifies as a thumbnail in my opinion, that's as wide as my entire screen.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...