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

profile: Support transparent icons (Trac #2648) #2648

Closed
elgg-gitbot opened this issue Feb 16, 2013 · 6 comments
Closed

profile: Support transparent icons (Trac #2648) #2648

elgg-gitbot opened this issue Feb 16, 2013 · 6 comments

Comments

@elgg-gitbot
Copy link

Original ticket http://trac.elgg.org/ticket/2648 on 40865051-12-17 by trac user hellekin, assigned to unknown.

Elgg version: 1.7

There are some ".jpg" hardcoded in different files.

The functionality to upload and save transparent PNG icons is trivial.

But finding the right path for an image is a bit more tricky: using $user->icon_imagetype or creating an IconEntity?

Should $user->getIcon() return the right format from file metadata or from its own?

It belongs to profile but some code in core could be affected (FileStore)

@elgg-gitbot
Copy link
Author

Milestone changed to Elgg 1.8.1 by ewinslow on 41199884-08-12

@elgg-gitbot
Copy link
Author

trac user twall wrote on 41347185-02-25

At first I looked at doing this by overriding the mod/profile upload actions (which have moved in 1.8), but that leaves un-fixed group icons and any other similar operations which might implement their own actions. So I looked to see if I could make a fix in a more central location.

The image resizing in filestore discards transparency information in converting to jpg.

Here is a partial solution to preserve transparency in filestore.php:get_resized_image_from_existing_file:

Insert this code immediately before the call to imagecopyresampled:

        // preserve transparency information, if any                            
        $trans = imagecolortransparent($original_image);
        $newsize = $params['newwidth'] * $params['newheight'];
        if ($trans >= 0) {
          $tc = imagecolorsforindex($original_image, $trans);
          $ti = imagecolorallocate($new_image, $tc['red'], $tc['green'], $tc['b\
lue']);
          imagefill($new_image, 0, 0, $ti);
          imagecolortransparent($new_image, $ti);
          $use_png = true;
        }
        // heuristic to use transparency only with icons/avatars                
        else if ($newsize <= 200*200) {
          // NOTE: most PNGs with transparency end up here                      
          imagealphablending($new_image, false);
          $color = imagecolorallocatealpha($new_image, 0, 0, 0, 127);
          imagefill($new_image, 0, 0, $color);
          imagesavealpha($new_image, true);
          $use_png = true;
        }

and then instead of always outputting jpeg:

        if ($use_png)
          imagepng($new_image);
        else
          // end famos                                                          
          imagejpeg($new_image, NULL, 90);

I haven't checked whether any callers of this function depend on the result being in jpeg format. I've also arbitrarily limited the size to 200x200, since you'll probably want jpeg for larger images, which aren't as likely as icons to have transparency.

Anyhow, the above patches work to allow transparency in uploaded user and group icons.

@elgg-gitbot
Copy link
Author

cash wrote on 41431226-06-23

Elgg needs a standard way to handle images (including routing without the full engine being loaded). I'm thinking that we can use something like the new cache handler that we added in 1.8.

@ewinslow
Copy link
Contributor

ewinslow commented Nov 6, 2014

@hypeJunction another images-related ticket :)

@ewinslow ewinslow added this to the Icons/uploads revamp milestone Nov 6, 2014
@hypeJunction
Copy link
Contributor

There are too many :) let's create a milestone for a rewrite. And let's agree on an image manipulation library

@ewinslow
Copy link
Contributor

Consolidating on #6152

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

No branches or pull requests

3 participants