Hi,

A very little typo in the code prevented (at least my installation) to have background colors being taken into account for 3 states buttons. The same color was used for all three states. See screenshots attached.

I attach one of of the smallest patches possible, which solves the issue for me : just a 3 characters difference with the original :)

Replace Line 800

  if (!$image->transparent && empty($image->bgimage[$idx])) {
    imagefilledrectangle ($image->im, $xofs, $yofs , $xofs + $width, $yofs+ $height, $image->background[$idx]);
  }

with

  if (!$image->transparent[0] && empty($image->bgimage[$idx])) {
    imagefilledrectangle ($image->im, $xofs, $yofs , $xofs + $width, $yofs+ $height, $image->background[$idx]);
  }

Hope this helps someone!

Jun.

Comments

jun’s picture

Title: No background colors used for three state mode. » Problem with background colors for three state mode.

I found another problem in the code which made it that the third background color wasn't taken into account.

It's an even smaller patch (a less or equal issue apparently), I'm just including the code change here:

Line 748.

  // pre allocate the colors
  for ($idx = 0; $idx < ($profile->threestate ? 3 : 1); $idx++) {

should be

  // pre allocate the colors
  for ($idx = 0; $idx <= ($profile->threestate ? 3 : 1); $idx++) {

How about including these baby patches in beta3?

Best,

Jun.

ronhoogwater’s picture

StatusFileSize
new816 bytes

Hello,

I have done some research as well, because my site depends on this functionality.
I agree with your first suggestion, Jun. After testing I applied your patch to my running website and it works great!

However there is another typo in line 760 that makes the first state background color always transparent, even if you have not set the transparent checkbox.

  if ($image->transparent) {
    // the background is transparent, but it should be the same colour as
    // whatever the image is over, otherwise you will get jagged edges
    // (unless you're using png).
    imagecolortransparent($image->im, $image->background[0]);
  }

I think there was meant

  if ($image->transparent[0]) {
    // the background is transparent, but it should be the same colour as
    // whatever the image is over, otherwise you will get jagged edges
    // (unless you're using png).
    imagecolortransparent($image->im, $image->background[0]);
  }

since $image->transparent is an array with only one item set.

But this enlights other problems:

  • When using transparency, only the first state background is parsed as transparent. The interface of the profile settings form suggests that for each state you can assign a different background color as transparent. This is impossible, so I think this should be made clear more in the form.
  • The comment suggests that when using png you will not get jagged edges, but I do get jagged edges when the transparent background color is different than the (css) background color.
  • I want to have only the first state transparent, so that only when you hover over the item there appears a colored box around the item. So actually the above typo serves my well now :) Fixing the typo might also break other sites. A workaround would be setting the background with css, but this results in jagged edges, as a result of the above two problems. I would like to achieve the same result in a more user-friendly way (like having transparency checkboxes for each of the states). But maybe this should be in a new feature request issue.

With comment #1 I do not agree. The original loops over $idx= 0, 1, 2. This seems correct to me, since $idx = 3 does not exist.

I attached a patch that fixes both typos.

edit: @Jun: I now realize I don't understand why you didn't have the problem with the first state background always being transparent (maybe a different php version?). And why your third background is not rendered. Does your suggestion in comment #1 fix this third background?

smoothify’s picture

Title: Problem with background colors for three state mode. » Fix transparency / no transparency issues
Version: 6.x-2.0-beta2 » 6.x-2.x-dev
Assigned: jun » Unassigned
StatusFileSize
new1.5 KB

I experienced similar issues with the transparency setting, especially when using multi-state images.

Even when i selected no transparency, the image was still transparent.

Here is a patch on the same lines as above that should fix it.