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

ResizeImage cannot resize gif #90804

Open
weiminghuaa opened this issue Sep 27, 2021 · 10 comments
Open

ResizeImage cannot resize gif #90804

weiminghuaa opened this issue Sep 27, 2021 · 10 comments
Labels
a: images Loading, displaying, rendering images found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@weiminghuaa
Copy link

CachedNetworkImage has memCacheWidth/memCacheHeight to reduce image memory, I think it implement by ResizeImage when look CachedNetworkImage src. But it's not work in gif, how to solve it?

ResizeImage.resizeIfNeeded(
          cacheWidth,
          cacheHeight,
          image,
        ),
@weiminghuaa
Copy link
Author

weiminghuaa commented Sep 27, 2021

#24835

@darshankawar darshankawar added the in triage Presently being triaged by the triage team label Sep 28, 2021
@darshankawar
Copy link
Member

@weiminghuaa
Are you referring / using https://pub.dev/packages/cached_network_image/install plugin ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 28, 2021
@weiminghuaa
Copy link
Author

@darshankawar Yes. I mean, I use the CachedNetworkImage memCacheWidth to reduce the memory usage of very large images. This method is effective for many image formats, such as webp and png, but it is not valid for gif. I see that CachedNetworkImage memCacheWidth is actually call ResizeImage resizeIfNeeded, so I want to ask if the problem lies in ResizeImage

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 28, 2021
@darshankawar
Copy link
Member

@weiminghuaa
What platform are you trying this on ? Is it possible to provide a self contained code only using ReSizeImage with a sample gif, that we can directly use to verify this ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 28, 2021
@weiminghuaa
Copy link
Author

weiminghuaa commented Sep 28, 2021

@darshankawar I have tested memory only using ReSizeImage with a sample gif. You can test the following code, no matter which way, the memory usage is 36.5M

截屏2021-09-28 21 07 18

class SampleItemDetailsView extends StatelessWidget {
  const SampleItemDetailsView({Key? key}) : super(key: key);

  static const routeName = '/sample_item';

  @override
  Widget build(BuildContext context) {
    // origin
    return Scaffold(
        appBar: AppBar(
          title: const Text('Item Details'),
        ),
        body: Center(
            child: Image.network(
          "https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif",
        )));
    // resize image
    return Scaffold(
        appBar: AppBar(
          title: const Text('Item Details'),
        ),
        body: Center(
            child: Image(
                image: ResizeImage.resizeIfNeeded(
                    375, // test code, set small to test memory
                    null,
                    const NetworkImage(
                      "https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif",
                    )))));
    // CachedNetworkImage
    return Scaffold(
      appBar: AppBar(
        title: const Text('Item Details'),
      ),
      body: Center(
        child: CachedNetworkImage(
          imageUrl:
              "https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif", // width: MediaQuery.of(context).size.width,
          width: MediaQuery.of(context).size.width,
          memCacheWidth: (MediaQuery.of(context).size.width *
                  MediaQuery.of(context).devicePixelRatio)
              .toInt(),
          fit: BoxFit.cover,
        ),
      ),
    );
  }
}

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 28, 2021
@darshankawar
Copy link
Member

body: Center(
child: Image(
image: ResizeImage.resizeIfNeeded(
375, // test code, set small to test memory
null,
const NetworkImage(
"https://d1hzxpwavt5kus.cloudfront.net/home/16322955386612_74ec4a82-bd04-4e91-93ed-5594e1778cc2.gif",
)))));

@weiminghuaa
If we consider above code snippet, since it uses core components and not 3rd party plugin, I see that above, you have provided only cacheWidth and kept cacheHeight as null.

Looking at the documentation, it states Composes the provider in a ResizeImage only when cacheWidth and cacheHeight are not both null.. So can you try by providing both parameters and see if it helps ?

https://api.flutter.dev/flutter/painting/ResizeImage/resizeIfNeeded.html

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 29, 2021
@weiminghuaa
Copy link
Author

I have try by providing both width and height, it's not work.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2021
@darshankawar
Copy link
Member

@weiminghuaa
How are you measuring the memory ?
Can you compare it with a sample image (png or jpeg, basically non-gif image) and see if it resizes and reflects in the memory you are measuring ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Sep 30, 2021
@weiminghuaa
Copy link
Author

I use Dart DevTools measure the memory. There is no problem with png or jpeg, but gif.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Oct 8, 2021
@darshankawar
Copy link
Member

Thanks for the update. I see the same behavior on latest stable and master.

stable, master flutter doctor -v
[✓] Flutter (Channel stable, 2.5.2, on Mac OS X 10.15.4 19E2269 darwin-x64,
    locale en-GB)
    • Flutter version 2.5.2 at /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3595343e20 (5 days ago), 2021-09-30 12:58:18 -0700
    • Engine revision 6ac856380f
    • Dart version 2.14.3

[✓] Android toolchain - develop for Android devices (Android SDK version 30)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dhs/Library/Android/sdk
    • Java binary at: /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.    

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.3, Build version 12C33
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)        

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 93.0.4577.82


• No issues found!

[✓] Flutter (Channel master, 2.6.0-12.0.pre.268, on Mac OS X 10.15.4 19E2269
    darwin-x64, locale en-GB)
    • Flutter version 2.6.0-12.0.pre.268 at
      /Users/dhs/documents/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b9d2177da0 (29 minutes ago), 2021-10-07 21:11:07 -0700
    • Engine revision 8d64613c9b
    • Dart version 2.15.0 (build 2.15.0-178.0.dev)

[✓] Android toolchain - develop for Android devices (Android SDK version 30)
    • Android SDK at /Users/dhs/Library/Android/sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = /Users/dhs/Library/Android/sdk
    • Java binary at: /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
    • All Android licenses accepted.    

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 12.5.1, Build version 12E507
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 4.1)
    • Android Studio at /Users/dhs/Library/Application Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/202.7486908/Android
      Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      1.8.0_242-release-1644-b3-6915495)        

[✓] VS Code (version 1.57.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.21.0

[[✓] Connected device (4 available)
    • Darshan's iphone (mobile)  • 21150b119064aecc249dfcfe05e259197461ce23 •
      ios            • iOS 14.4.1 18D61
    • iPhone 12 Pro Max (mobile) • A5473606-0213-4FD8-BA16-553433949729     •
      ios            • com.apple.CoreSimulator.SimRuntime.iOS-14-3 (simulator)
    • macOS (desktop)            • macos                                    •
      darwin-x64     • Mac OS X 10.15.4 19E2269 darwin-x64
    • Chrome (web)               • chrome                                   •
      web-javascript • Google Chrome 93.0.4577.82


• No issues found!




@darshankawar darshankawar added a: images Loading, displaying, rendering images found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on and removed in triage Presently being triaged by the triage team labels Oct 8, 2021
@goderbauer goderbauer added the P2 Important issues not at the top of the work list label Mar 23, 2022
@flutter-triage-bot flutter-triage-bot bot added team-framework Owned by Framework team triaged-framework Triaged by Framework team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: images Loading, displaying, rendering images found in release: 2.5 Found to occur in 2.5 found in release: 2.6 Found to occur in 2.6 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

3 participants