Skip to content

ResizeImage cannot resize gif  #90804

Closed

Description

@weiminghuaa

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,
        ),

Activity

  1. weiminghuaa commented on Sep 27, 2021

    @weiminghuaa
    Author
  2. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 28, 2021
  3. weiminghuaa commented on Sep 28, 2021

    @weiminghuaa
    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

  4. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 28, 2021
  5. darshankawar commented on Sep 28, 2021

    @darshankawar
    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 ?

  6. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 28, 2021
  7. weiminghuaa commented on Sep 28, 2021

    @weiminghuaa
    Author

    @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,
            ),
          ),
        );
      }
    }
    
  8. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 28, 2021
  9. darshankawar commented on Sep 29, 2021

    @darshankawar
    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

  10. added
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 29, 2021
  11. weiminghuaa commented on Sep 30, 2021

    @weiminghuaa
    Author

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

  12. removed
    waiting for responseThe Flutter team cannot make further progress on this issue until the original reporter responds
    on Sep 30, 2021
  13. darshankawar commented on Sep 30, 2021

    @darshankawar
    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 ?

  14. 6 remaining items

  15. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Oct 8, 2021
  16. added
    P2Important issues not at the top of the work list
    on Mar 23, 2022
  17. snailflying commented on Aug 14, 2024

    @snailflying

    Oh,it is since 2021,Now is 2024! Is there any progress?

  18. mohamedalsamrai commented on Oct 27, 2026

    @mohamedalsamrai
    Contributor

    Finally Done

  19. github-actions commented on Nov 10, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  20. locked as resolved and limited conversation to collaborators on Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work lista: imagesLoading, displaying, rendering imagesfound in release: 2.5Found to occur in 2.5found in release: 2.6Found to occur in 2.6frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions