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

Palette.getMostUsedColors() getting different values depending on OS / PHP version #45

Open
bgaillard opened this issue Aug 10, 2016 · 7 comments

Comments

@bgaillard
Copy link

Hi, I just started to use color-extractor in one or our customer's project.

We wrote a unit test to check our code and it appears the Palette.getMostUsedColors() function is not returning de same results depending on the OS and/or PHP version in use (perhaps this could also be dependent on the GD version which is installed on the machine).

For exemple on a Unix machine we get this array (the limit parameter is equal to 12 and the index of this array has been converted to hexadecimal).

[
    '#000000' => 93285,
    '#010000' => 7871,
    '#020001' => 6022,
    '#010101' => 3413,
    '#040000' => 3321,
    '#000002' => 2070,
    '#050100' => 2036,
    '#030000' => 1945,
    '#000100' => 1789,
    '#060000' => 1668,
    '#020100' => 1604,
    '#634D40' => 1263,
]

On a Windows machine and with the same image we get the following values.

[
    '#000000' => 93135,
    '#010000' => 7710,
    '#020001' => 6001,
    '#010101' => 3377,
    '#040000' => 3227,
    '#000002' => 2056,
    '#050100' => 2052,
    '#000100' => 1842,
    '#030000' => 1747,
    '#020100' => 1580,
    '#060000' => 1557,
    '#634D40' => 1264,
]

We only encounter this problem with one testing JPEG file (I can provide you the file if needed).

We also have similar unit test with GIF and PNG files, with those formats we do not encounter any problem.

So do you know what could cause differences in our case ?

  • Could it be caused by the GD version installed on the machine ? Also perhaps their are difference between the Windows and Unix GD libraries ?
  • Could it be caused by the PHP version in use ?
  • Or are they potential rounded values in the source code which could be different between platforms ?

If it can help here are much more details about each testing envirronment

  • Windows 10 Pro 64bits, PHP 7.0.8
  • Centos 7 64bits, PHP 7.0.8

If the problem is linked to GD perhaps doing the same test with #37 could be interesting.

In any case I the problem cannot be solved IMO it should be described and explained in the README.

Thanks

@MatTheCat
Copy link
Member

I witnessed a similar problem between GD and Imagick on the same environment. Sadly I have no idea if it's related or what is causing this.

@bgaillard
Copy link
Author

bgaillard commented Aug 10, 2016

@MatTheCat Thanks for those additional informations, I also encounter diffrencies with the https://github.com/jenssegers/imagehash library.

I'm not 100% sure but in my opinion JPEG files (and perhaps other kind of files) are not treated the same way depending on the OS / PHP / GD versions in use.

For example this Stackoverflow post http://stackoverflow.com/questions/10647266/image-file-size-differences-between-imagemagick-and-gd-library indicates.

It turns out that JPEG quality scales are not defined in a specification or standard, and they are not uniform across encoders. A quality of 60 in Photoshop might be the same as a quality of 40 in one program, quality B+ in another and quality fantastico in a third. In my tests, I found that Photoshop’s 60 is closest to -quality 82 in ImageMagick.

Perhaps this issue is also similar Intervention/image#355.

Does anyone know if this supposition is correct or have much more informations about those differencies ?

@MatTheCat
Copy link
Member

I don't think the problem comes from compression as I saw a difference between GD and Imagick with the exact same image.

@MelnikDima
Copy link

Handled the similar problem that Imagemagic and gd calculates different number of unique colors
imagemagic(279123) vs gd(279069) on the exact same image (difference on a lot of tested images is approximately 100)

@MatTheCat
Copy link
Member

@MelnikDima how did you handle it?

@MelnikDima
Copy link

@MatTheCat something like
$image->getImageColors(); // unique colors by Image magic

$palette = Palette::fromFilename($file);
$palette_count = count($palette); // unique_colors by gd

@MatTheCat
Copy link
Member

Maybe the best course would be to just ignore these differences 🤔

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

3 participants