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

<Picture> element inflates image sizes #11166

Closed
1 task
NateWr opened this issue May 30, 2024 · 2 comments
Closed
1 task

<Picture> element inflates image sizes #11166

NateWr opened this issue May 30, 2024 · 2 comments
Labels
feat: assets Related to the Assets feature (scope) needs response Issue needs response from OP

Comments

@NateWr
Copy link

NateWr commented May 30, 2024

Astro Info

Astro                    v4.9.2
Node                     v18.17.1
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

When using the <Picture> element to generate smaller image sizes from a source image, Astro produces images with an inflated file size. Images exceed the original file size by as much as 3x.

What's the expected result?

I expect the file size to be no larger than the source image and in many cases smaller than the original image.

The specific code for the reproduction can be found here: https://github.com/NateWr/astro-image-reproduction/blob/main/src/pages/index.astro. (I was unable to reproduce any asset manipulation in Stackblitz -- perhaps this is disabled for security/performance.)

The source image is ~443kb:

$ ls -la src/images 
total 444
drwxrwxr-x 2 nate nate   4096 May 30 10:46 .
drwxrwxr-x 6 nate nate   4096 May 30 10:43 ..
-rw-rw-r-- 1 nate nate 443126 May 30 10:46 city.png

When running npm run build, the following images and sizes are generated:

$ ls -la dist/_astro   
total 3144
drwxrwxr-x 2 nate nate    4096 May 30 10:47 .
drwxrwxr-x 3 nate nate    4096 May 30 10:47 ..
-rw-rw-r-- 1 nate nate 1422477 May 30 10:47 city.tXwVt3cZ_1LlvWd.png
-rw-rw-r-- 1 nate nate  214630 May 30 10:47 city.tXwVt3cZ_GFUrO.png
-rw-rw-r-- 1 nate nate  443126 May 30 10:47 city.tXwVt3cZ.png
-rw-rw-r-- 1 nate nate   85194 May 30 10:47 city.tXwVt3cZ_Z1czD1B.webp
-rw-rw-r-- 1 nate nate  847156 May 30 10:47 city.tXwVt3cZ_Z1NjJbt.png
-rw-rw-r-- 1 nate nate   27330 May 30 10:47 city.tXwVt3cZ_Z2eeOM5.webp
-rw-rw-r-- 1 nate nate  156872 May 30 10:47 city.tXwVt3cZ_ZUquXj.webp

Link to Minimal Reproducible Example

https://github.com/NateWr/astro-image-reproduction

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label May 30, 2024
@matthewp
Copy link
Contributor

Can you try passing quality={80}? Wondering if this could be the underlying issue for you: lovell/sharp#3371

@matthewp matthewp added needs response Issue needs response from OP feat: assets Related to the Assets feature (scope) and removed needs triage Issue needs to be triaged labels May 30, 2024
@NateWr
Copy link
Author

NateWr commented May 30, 2024

Yes, that brings file sizes down to a more expected range:

$ ls -la dist/_astro
total 1556
drwxrwxr-x 2 nate nate   4096 May 30 12:35 .
drwxrwxr-x 3 nate nate   4096 May 30 12:35 ..
-rw-rw-r-- 1 nate nate 293209 May 30 12:35 city.tXwVt3cZ_1aVQ0G.png
-rw-rw-r-- 1 nate nate  85194 May 30 12:35 city.tXwVt3cZ_2omDQW.webp
-rw-rw-r-- 1 nate nate 443126 May 30 12:35 city.tXwVt3cZ.png
-rw-rw-r-- 1 nate nate 491262 May 30 12:35 city.tXwVt3cZ_Z1O9l35.png
-rw-rw-r-- 1 nate nate 156872 May 30 12:35 city.tXwVt3cZ_Z2eVdgC.webp
-rw-rw-r-- 1 nate nate  76763 May 30 12:35 city.tXwVt3cZ_Z2jxQ4m.png
-rw-rw-r-- 1 nate nate  27330 May 30 12:35 city.tXwVt3cZ_ZX6gIS.webp

Thanks!

@NateWr NateWr closed this as completed May 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: assets Related to the Assets feature (scope) needs response Issue needs response from OP
Projects
None yet
Development

No branches or pull requests

2 participants