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

PNG images not optimized #179

Open
mrgoonie opened this issue Jul 29, 2020 · 5 comments
Open

PNG images not optimized #179

mrgoonie opened this issue Jul 29, 2020 · 5 comments

Comments

@mrgoonie
Copy link

While JPG works fine, PNG images don't seem to be optimized.

page/index.js

export default function Home(){
  return (<img src={require("../images/[email protected]?url")} width={500} />)
}

next.config.js

const withPlugins = require('next-compose-plugins');
const optimizedImages = require('next-optimized-images');

module.exports = withPlugins([
  [
    optimizedImages,
  ]
])

package.json

{
  "name": "next-imagemin",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start"
  },
  "dependencies": {
    "file-loader": "^6.0.0",
    "imagemin-gifsicle": "^7.0.0",
    "imagemin-mozjpeg": "^9.0.0",
    "imagemin-optipng": "^8.0.0",
    "imagemin-pngquant": "^9.0.0",
    "imagemin-svgo": "^8.0.0",
    "imagemin-webpack-plugin": "^2.4.2",
    "next": "9.4.4",
    "next-compose-plugins": "^2.2.0",
    "next-optimized-images": "^2.6.1",
    "node-sass": "^4.14.1",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "responsive-loader": "^2.0.0",
    "sass": "^1.26.10",
    "sharp": "^0.25.4",
    "styled-jsx-plugin-sass": "^1.0.0",
    "url-loader": "^4.1.0",
    "webp-loader": "^0.6.0"
  },
  "devDependencies": {
    "copy-webpack-plugin": "^6.0.3"
  }
}

And the image is: /images/[email protected]
thumb-large@2x

.next/static/images/[email protected]
thumb-large@2x-a906e213f32c5020bd4dffa9c9641d51

...Or am I doing something incorrectly?

@cyrilwanner
Copy link
Owner

Hi @mrgoonie
I see in your package.json that you have imagemin-optipng and imagemin-pngquant installed. I'm not sure, but this could be the reason that next-optimized-images gets confused because of that. You usually only want to use one optimization library for png images. Can you try to uninstall imagemin-pngquant so you only have imagemin-optipng installed (which is more commonly used) and see if that changes anything?

@mrgoonie
Copy link
Author

Thanks for the response, I tried your suggestion, but the result is still the same 😢

@efeminella
Copy link

I'm having the same issue, installed imagemin-optipng and next-optimized-images, however, when .png image sizes remain the same as before installing and adding the plugin.

@cyrilwanner
Copy link
Owner

I recommend using the canary version in this case as it is a complete rewrite and image optimization was moved to WebAssembly and so it works the same in every environment. It solves all current issues and can already be considered stable, just a few features are missing before I will publish it as a non-canary version.

I am sorry that I don't have enough time to investigate this problem in the v2 version. But I want to invest most of my time in the canary version to be able to publish it as soon as possible and resolve all open issues. And it is also possible that this issue is not even caused by next-optimized-images as it uses a 3rd party webpack loader internally which calls the imagemin plugins.

@krystof-k
Copy link

I'm facing the same issue even using the canary version. JPG is optimized (e.g. 1.7 MB to 400 kB), but PNG is even bigger than the original (15.5 MB to 15.6 MB).

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

No branches or pull requests

4 participants