GithubHelp home page GithubHelp logo

Comments (8)

lucasRolff avatar lucasRolff commented on May 27, 2024 1
  1. Add a processing option that will enable the fallback to the original image no matter what. It will be the caller's responsibility to decide if they want the fallback (i.e. use that processing option only when the resizing option is not used).

But isn't that just skp? Or are you thinking the processing option would do the fallback to the original image only if the size of the "processed" one is larger?

  1. Change every processing step so it indicates if it actually changed the image.

At least from my POV, what I'm after boils down to that not every image will have some kind of resize/blur/watermark/etc processing done, but may still utilize webp/avif processing, but if e.g. the client does not support webp or avif, one would usually want to deliver in the original format (png -> png, gif -> gif, jpeg -> jpeg for example), but if we end up with larger images we only made the experience worse for the user.

That's why I'd love a "flag" to say, if processed image is larger, then use the original.

I'd love to do the PR if I had any sense of Go experience πŸ˜…

from imgproxy.

DarthSim avatar DarthSim commented on May 27, 2024 1

@divaltor

even if we imagine that we send already compressed images (I can guarantee that we don't)

I can guarantee that you do. Only a few image formats like BMP or ICO (and very rarely – TIFF) store image data uncompressed.

100% quality of image -> q:85 -> 85%
85% quality of image -> q:85 -> 85*0.85 -> 72.25%

This is not how image compression works.

First of all, PNG does not have a quality factor since it is a lossless format (unless it is a paletted PNG). Yet it can be saved with different compression levels. As I said before, imgproxy doesn't use the maximum compression level for performance reasons.

But formats like JPEG do lossy compression. I won't describe the whole JPEG compression algorithm here, but the most important part is that it does discrete cosine transform (DCT) and removes some data according to the quantization table. When imgproxy (or any other image processing tool) needs to process an image, it decodes it to raw pixels and encodes it back in the end. If you encode it with a larger quality factor, less data will be discarded, and thus file size will be larger. You can ask: "How it can discard less data that was discarded during the initial encoding?" The thing is that the result of DCT will be different as raw pixels are changed.

from imgproxy.

divaltor avatar divaltor commented on May 27, 2024

I found the same issue with images in PNG format -> PNG format with compression (q:0 preset and format_quality: png=75). Original image is ~640 KB, compressed by imgproxy results in ~680 KB somehow and I can't understand why.

Would be nice if someone could describe that behavior, because it's kinda weird to see compressed image larger than original image

from imgproxy.

DarthSim avatar DarthSim commented on May 27, 2024

Hey everyone,

Well, we have two options here:

  1. Add a processing option that will enable the fallback to the original image no matter what. It will be the caller's responsibility to decide if they want the fallback (i.e. use that processing option only when the resizing option is not used).
  2. Change every processing step so it indicates if it actually changed the image.

Anyway, PRs are always welcome πŸ˜‰

Would be nice if someone could describe that behavior, because it's kinda weird to see compressed image larger than original image

Unless the original is BMP or something like that, it is compressed too. The size may increase for various reasons. In the case of JPEG, the original may be saved with lower quality than you set for imgproxy. In the case of PNG, it may be saved with a higher level of compression than imgproxy uses. imgproxy uses compression level 6 for PNGs as it is a good compromise between speed and the resulting size. Higher levels of compression dramatically slow encoding. However, having a config for this would be nice, I guess.

from imgproxy.

divaltor avatar divaltor commented on May 27, 2024

In the case of JPEG, the original may be saved with lower quality than you set for imgproxy. In the case of PNG, it may be saved with a higher level of compression than imgproxy uses. imgproxy uses compression level 6 for PNGs as it is a good compromise between speed and the resulting size.

I don't undestand it very well, but even if we imagine that we send already compressed images (I can guarantee that we don't) how imgproxy actually "restore" information for compressed image and return a file larger than we pass to imgproxy? Otherwise I can't describe what's happening in that case

100% quality of image -> q:85 -> 85%

85% quality of image -> q:85 -> 85*0.85 -> 72.25%

I can't see a case when we get a better image than we provide to imgproxy

UPD: I even tried to compare images with PSNR, but it showed me that images are equal (when I used q:0 preset with config formatQuality: png=75)

from imgproxy.

DarthSim avatar DarthSim commented on May 27, 2024

But isn't that just skp? Or are you thinking the processing option would do the fallback to the original image only if the size of the "processed" one is larger?

Yup, this is what I was talking about.

I'd love to do the PR if I had any sense of Go experience πŸ˜…

Neither did I a few years ago πŸ™‚ I mean, I could do this myself, but I can't give you any estimations on when this will be done.

from imgproxy.

divaltor avatar divaltor commented on May 27, 2024

Thanks for the describing the de-encoding process, I'll test then a few more times with different presets to ensure that problem is not on imgproxy side

from imgproxy.

lucasRolff avatar lucasRolff commented on May 27, 2024

but I can't give you any estimations on when this will be done.

No worries at all! I just thought it would be an overall nice improvement

I'll likely buy the pro version in the coming days regardless for the more intelligent optimization logic it has, and hope it can help a bit anyway (among some other cool features that I would love to utilize)

Thank you for an amazing piece of software regardless!

from imgproxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.