1

In GIMP I can save an image for Web with these properties:

enter image description here

  • PNG-8
  • 256 colors palette
  • Dither: Floyd-Steinberg / Floyd-Steinberg 2 / positioned

With these options I can reduce upto about 70% of the size of the image file without evident quality loss.

How can I get the same result with PHP?

The resulting image must preserve transparency.

I know almost nothing about image compression, encoding, palette, etc.

Edit: I posted a new question with a PHP script to do that, so I'll close this question or I'll answer it.

PHP wrong result for imagetruecolortopalette with PNG with transparency

halfer
  • 19,824
  • 17
  • 99
  • 186
user2342558
  • 5,567
  • 5
  • 33
  • 54
  • You might want to mention that you can't install libraries as you said [here](https://stackoverflow.com/questions/57972413/lossy-compression-of-png-in-php-without-installing-anything-on-the-server). And you might just want to [implement the dithering yourself](https://en.wikipedia.org/wiki/Floyd%E2%80%93Steinberg_dithering), it's not that complicated. – Tox Sep 17 '19 at 12:39
  • 2
    In a comment on the other question, you said, _“I need the best quality preservation, because they are high-resolution photos.”_ – and now we’re gonna pretend an 8-bit palette image would actually satisfy those requirements? You must either be kidding, or you are doing a bad job at describing what you actually need in the first place. (Plus you kinda brought that as a counter-argument over there, when someone originally suggested you go with a palette-based format …) – 04FS Sep 17 '19 at 12:42
  • @04FS By doing that GIMP preserves the visible quality I need. English isn't my mother language, so I may bad wrote something. But this is a different, but similar, question: here I'm asking specifically for the replication of what GIMP can do. – user2342558 Sep 17 '19 at 12:50
  • @Tox here I do not preclude the option to install some library (in the localhost) – user2342558 Sep 17 '19 at 12:51
  • See my earlier comment, just implement the dithering yourself and go with PHP's `image*` functions, or [look here](https://www.php.net/manual/en/function.imagetruecolortopalette.php). – Tox Sep 17 '19 at 12:55
  • Maybe with PHP Imagick... https://stackoverflow.com/a/13335428/2836621 – Mark Setchell Sep 17 '19 at 13:26
  • @Tox you says "it's not that complicated" but it sound to me: learn a lot before being able to reproduce it with PHP in an efficient way :) – user2342558 Sep 17 '19 at 15:59
  • [Here's](https://gist.github.com/Toxyl/107b56499cbfe5a7a08710070a270251) an implementation of dithering with different algorithms. It's ActionScript 3, I'll leave it up to you to translate it to PHP. ;) – Tox Sep 17 '19 at 16:13
  • thanks, I'll study it :) – user2342558 Sep 17 '19 at 19:49
  • Guys, please see my edit. – user2342558 Sep 18 '19 at 11:55

0 Answers0